在Android上实施Google Play应用程序静默安装功能 [英] Implementing Google Play Application Silent Install Feature On Android

查看:84
本文介绍了在Android上实施Google Play应用程序静默安装功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,专家/黑客,

我正在尝试在Android上实现Google Play应用程序静默安装功能(类似于appbrain快速网络安装程序).

I'm trying to implement the Google Play application silent install feature (similar to appbrain fast web installer) on android.

到目前为止,我能够实现以下目标:

So far I was able achieve the following :

  1. 找出一种方法来检索Google Play身份验证令牌(从而为我的应用授予与手机上的Google Play应用进行通话的权限).我在下面列出了用于此目的的代码:

  1. Find out a method to retrieve the Google Play Auth Token (thus granting permission for my application to talk with Google Play application on the Phone). I've listed the code I've used for this below :

    Log.i(TAG,"Getting the Google Play Auth Token Using Account Manager : START");
    AccountManager accountManager = AccountManager.get(getApplicationContext());
    Account[] accArr = accountManager.getAccountsByType("com.google");

    for (Account acc : accArr) {
        Log.i(TAG, "For Account Name : " + acc.name + " - "+ "Account Type : " + acc.type);
        accountManager.getAuthToken(acc, "googleplay", null, this,new AccountManagerCallback<Bundle>() {

                    public void run(
                            AccountManagerFuture<Bundle> paramAccountManagerFuture) {
                        try {
                            Bundle localBundle = (Bundle) paramAccountManagerFuture.getResult();
                            String authToken = localBundle.get("authtoken") + "";

                            Log.i(TAG, "Got AuthToken : " + authToken);

                        } catch (Exception ex) {
                            StackTraceElement[] starray = ex.getStackTrace();
                            StringBuffer bf = new StringBuffer();
                            bf.append("Error : " + ex.getMessage()).append("\n");
                            for (StackTraceElement ste : starray) {
                                bf.append(ste.toString()).append("\n");
                            }
                            Log.e(TAG, bf.toString());
                        }

                    }

                }, null);
    }
    Log.i(TAG,"Getting the Google Play Auth Token Using Account Manager : END")

  • 了解如何获取手机的Android ID(我认为,当我向Android手机上的GPlay服务器或Gplay/自动贩卖应用发送appInstall请求时,应该使用此ID)

  • Find out how to Retrieve the Android-Id of the Phone (This Id as I believe should be used when sending the appInstall request to the GPlay Servers or the Gplay/vending application on the android phone)

      Log.i(TAG, "Getting the Android ID Of the Phone : START");
    
        Uri localUri = Uri.parse("content://com.google.android.gsf.gservices");
        ContentResolver localContentResolver = getContentResolver();
        String[] arrayOfString = new String[1];
        arrayOfString[0] = "android_id";
        Cursor localCursor = localContentResolver.query(localUri, null,null, arrayOfString, null);
        Log.i(TAG, "Column Count : " + localCursor.getColumnCount());
        if ((localCursor != null) && (localCursor.moveToFirst())) {
            String androidId = Long.toHexString(Long.parseLong(localCursor.getString(1)));
            Log.i(TAG, "Received Android ID : " + androidId);
    
            Log.i(TAG,"Other Value in Column : " + localCursor.getString(0));
        }
    
        Log.i(TAG,"Getting the Android ID of the Phone : END");
    

  • 找出要发送到手机上的Google Play服务器或Gplay/自动贩卖应用程序的协议缓冲区请求,以启动静默应用程序下载和下载;安装过程.

  • Find out the Protocol Buffer Request to be sent to the Google Play servers or the Gplay/vending application on the phone to Initiate the silent application download & install process.

    message InstallRequest {
    optional string appId = 1;
    }
    message RequestContext {
    required string authSubToken = 1;
    required bool isSecure = 2;
    required int32 version = 3;
    required string androidId = 4;
    optional string deviceAndSdkVersion = 5;
    optional string userLanguage = 6;
    optional string userCountry = 7;
    optional string operatorAlpha = 8;
    optional string simOperatorAlpha = 9;
    optional string operatorNumeric = 10;
    optional string simOperatorNumeric = 11;
    
    }
    message Request {
    optional RequestContext context = 1;
    repeated group RequestGroup = 2 {
    optional InstallRequest installRequest = 10;
    }
    }
    

  • 4.我什至使用了protobuf编译器,并生成了用于处理上述协议缓冲区请求的java类,并使用一些示例数据填充了上述协议缓冲区字段.参见下面的代码:

    4.I even used the protobuf compiler and generated the java class for manipulating the above protocol buffer request and filled the above protocol buffer fields with some sample data. See the code below :

        public void buildAndSendSilentInstallProtoBuffMessage(String gplayAuthToken, String deviceAndroidId){
    
        try{
        /*
         * The Root Request Object Assumed to be Holding the Silent Install Request
         */
        Request.Builder request = Request.newBuilder(); 
    
        //Populating the ReequestContext Object
        RequestContext.Builder context = RequestContext.newBuilder();
    
        context.setAndroidId(deviceAndroidId);
        context.setAuthSubToken(gplayAuthToken);
    
        context.setIsSecure(true);
        context.setVersion(1002);
        context.setDeviceAndSdkVersion("dream:4");
        context.setUserLanguage("en");
        context.setUserCountry("us");
        context.setOperatorAlpha("Android");
        context.setOperatorNumeric("310260");
        context.setSimOperatorNumeric("310260");
    
        //Building the Install Request
        InstallRequest.Builder installRequest = InstallRequest.newBuilder();
        installRequest.setAppId("-2564446724934482383");
    
        //Setting the Install Request to the Request Group
        RequestGroup.Builder requestGroup = RequestGroup.newBuilder();
        requestGroup.setInstallRequest(installRequest);
    
        //Setting the Request Context to the Main Request Object
        request.setContext(context);
    
        //Setting the Request Group to the Request Object
                request.addRequestGroup(requestGroup);
    

    GPlay令牌和Android ID的示例数据如下:

    The Sample Data for GPlay Token and the Android Id are as follows :

    1. Android_ID:

    3a0f901831a0f402

    3a0f901831a0f402

    1. Google Play AuthToken:

    DQAAAMgAAACpOyPf6apRbb0i4qhTVaf0yYoikTAb4TYlHCRLrW 4mu5f14j-H35KGmO9TQKUDYCfj3-B-QIH5chfXT3bS02Uxljg7vYt4I-kgXLEJwPcynjugDcJ9fYPOh1c2FnOnywFXXxXw6hcqs5sVnJEt 5zW2ditoB5VeeXG9Zfodj9dXKobObi50-XnHoGfWi2b64Uf3EHGdQTsDCMzfZrE4mb22fr9LCW1oZG5tkzw S4KhPBHWMN2fO7w-1IZ4UK5LOI80vPBLjxBaavKAXHoVUHSNV

    DQAAAMgAAACpOyPf6apRbb0i4qhTVaf0yYoikTAb4TYlHCRLrW 4mu5f14j-H35KGmO9TQKUDYCfj3-b-QIH5chfXT3bS02Uxljg7vYt4I-kgXLEJwPcynjugDcJ9fYPOh1c2FnOnywFXXxXw6hcqs5sVnJEt 5zW2ditoB5VeeXG9Zfodj9dXKobObi50-XnHoGfWi2b64Uf3EHGdQTsDCMzfZrE4mb22fr9LCW1oZG5tkzw S4KhPBHWMN2fO7w-1IZ4UK5LOI80vPBLjxBaavKAXHoVUHSNV

    1. 在Gplay应用程序无提示安装过程中,我还使用了扎根的银河系手机进行了嗅探,并发现了两个HTTP GET请求.

    我尝试重现使用Shark root捕获的那两个Http GET请求(使用我已扎根的android galaxy nexus手机),而第一个请求只是下载Market File本身(我能够将其保存到手机的SD卡中)但是,它必须像任何未知源应用程序一样安装),而第二个请求什么也不会返回.

    I tried reproducing the those two Http GET requests captured using Shark for root(using my rooted android galaxy nexus phone) and the 1st Request just downloads the Market File itself (which I was able to save to the SD card of the Phone. But then it has to be installed like any unknown sources application) while the second request returns nothing.

    捕获的两个获取请求如下所示:

    The two get requests captured are shown below :

    1. 获取一个请求:

    1. GET REQUEST ONE :

    21 0.827240 192.168.135.102 173.194.36.4 HTTP 535 GET /market/download/Download?                                                                     packageName=com.gau.go.launcherex.theme.appwidget.gopowermaster.futureworld&versionCode=1&token=AOTCm0QRnH3rmypWtCGoAL_SU1BSt311wpyz-_LZTodkUSAlc-             f5SrdMiz5WDRDUKMMm6S3plBI9Jbh1tukT1jyCYXLgP4QhVvZvn5JLtZQ&downloadId=-165214892049282883 HTTP/1.1
    
     Which has the following http headers :
    
    Cookie: MarketDA=17214805622679635526\r\n
    Host: android.clients.google.com\r\n
    Connection: Keep-Alive\r\n
    User-Agent: AndroidDownloadManager/4.1.1 (Linux; U; Android 4.1.1; Galaxy Nexus Build/JRO03C)\r\n
    

  • 获取两个请求:

  • GET REQUEST TWO :

    44    6.595093    192.168.135.102    222.165.163.15    HTTP    608    GET /market/GetBinary/com.gau.go.launcherex.theme.appwidget.gopowermaster.futureworld/1?expire=1346838270&ipbits=0&ip=0.0.0.0&cp=SnpybWlzSFk6OTYzMzg0MTE2NzA1ODEwOTYxMjE&sparams=expire,ipbits,ip,q:,cp&signature=2C0778C4635F6F8AE1DA8479FB08DCB9BC04C2E9.60202D8D4D2FDDA70609A3862A25852F0BAA2766&key=am2 HTTP/1.1
    
    Which has the following http headers :
    
    Cookie: MarketDA=17214805622679635526\r\n
    Host: o-o.preferred.slt-cmb2.v12.lscache4.c.android.clients.google.com\r\n
    Connection: Keep-Alive\r\n
    User-Agent: AndroidDownloadManager/4.1.1 (Linux; U; Android 4.1.1; Galaxy Nexus  Build/JRO03C)\r\n
    

  • 我已经研究了大约两个星期,但仍然找不到以下内容:

    I've been looking into this for about two weeks now but I still couldn't find the following :

    1. AppBrain快速Web安装程序是否使用协议缓冲区来调用电话或Gplay服务器上的Gplay(自动售货应用程序)?如果是这样,则以上协议缓冲区请求格式正确吗??.

    1. Whether the AppBrain fast Web Installer uses the protocol buffer to invoke the Gplay (vending application) on the phone or the Gplay servers ?. If so is the above Protocol Buffer Request format correct ??.

    如果上述协议缓冲区请求格式正确,那么我应该将协议缓冲区请求发送到Phone或Gplay服务器中的何处,以调用静默应用程序"下载和安装过程?.

    If the Above Protocol Buffer Request format is correct then to Where in the Phone or Gplay server should I send the Protocol buffer request to to invoke the Silent Application download and installing procedure ?.

    我也有一个C2DM(现为GCM)服务器和与此任务相关的客户端设置.有人能指出我正确的方向还是给我提供解决此问题的任何线索?任何帮助都将不胜感激.

    I also have a C2DM (now GCM) server and client setup around this task as well. Could anyone point me in the correct direction or give me any clues for solving this ?. Any help is much appreciated .

    推荐答案

    只有通过Google Play才能在Google Experience设备上进行静默安装.通常,只有预先加载到硬件上的商店才能完成此操作,因为它们需要使用操作系统的签名密钥.

    Silent install on Google Experience devices is only possible by Google Play. More generally, only stores that come preloaded on your hardware can accomplish this, since they need to use the operating system's signing key.

    这是出于安全原因.用户需要能够接受新安装的权限.操作系统无法验证非官方商店是否已正确执行此操作.

    This is for security reasons. Users need to be able to accept permissions for new installations. The OS has no way to verify whether non-official stores have properly done this.

    第三方应用程序必须使用PackageManager安装新应用程序,这将代表您显示权限并需要用户的明确许可.

    Third-party applications must use PackageManager to install new apps, which will display permissions on your behalf and require an explicit user approval.

    尝试绕过此操作可能属于Google Play DDA的禁止操作"条款,该条款使您的开发者帐户面临被暂停的风险.不要这样做.

    Attempting to circumvent this may fall under the "prohibited actions" clause of the Google Play DDA, which puts your developer account at risk for suspension. Don't do it.

    这篇关于在Android上实施Google Play应用程序静默安装功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆