android - 在 Android 上实现 Google Play 应用静默安装功能

标签 android

嗨专家/黑客专家,

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

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

  1. 找出一种方法来检索 Google Play 授权 token (从而授予我的应用程序与手机上的 Google Play 应用程序对话的权限)。我在下面列出了我为此使用的代码:

        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")
    
  2. 了解如何检索手机的 Android-Id(我认为在向 GPlay 服务器或 Android 手机上的 Gplay/贩卖应用程序发送 appInstall 请求时应该使用此 Id)

      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");
    
  3. 找出要发送到 Google Play 服务器或手机上的 Gplay/销售应用程序的 Protocol Buffer 请求,以启动静默应用程序下载和安装过程。

    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 类来处理上面的 Protocol Buffer 请求,并用一些示例数据填充了上面的 Protocol Buffer 字段。请参阅下面的代码:

    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 Token 和 Android Id 的示例数据如下:

  1. Android_ID :

3a0f901831a0f402

  1. Google Play 授权 token :

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

  1. 在 Gplay 应用程序静默安装期间,我还使用我的 root 的 galaxy nexus 手机进行了一些嗅探,发现只有两个 HTTP GET 请求。

我尝试重现使用 Shark 为 root 捕获的那两个 Http GET 请求(使用我的 root android galaxy nexus 手机),第一个请求只是下载市场文件本身(我能够将其保存到手机的 SD 卡中. 但是它必须像任何未知来源的应用程序一样安装)而第二个请求不返回任何内容。

捕获到的两个get请求如下图:

  1. 获取请求一:

    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
    
  2. 获取请求二:

    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
    

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

  1. AppBrain 快速 Web 安装程序是否使用 Protocol Buffer 调用手机或 Gplay 服务器上的 Gplay(自动售货应用程序)?如果是这样,上述 Protocol Buffer 请求格式是否正确??。

  2. 如果上述 Protocol Buffer 请求格式正确,那么我应该将 Protocol buffer 请求发送到 Phone 或 Gplay 服务器的哪个位置以调用静默应用程序下载和安装程序?

我还围绕此任务设置了 C2DM(现在是 GCM)服务器和客户端。谁能指出我正确的方向或给我解决这个问题的任何线索?非常感谢任何帮助。

最佳答案

Google 体验设备上的静默安装只能通过 Google Play 进行。更一般地说,只有预加载到您的硬件上的商店才能完成此操作,因为它们需要使用操作系统的签名 key 。

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

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

试图规避这一点可能属于 Google Play DDA 的“禁止行为”条款,这会使您的开发者帐户面临被暂停的风险。不要这样做。

关于android - 在 Android 上实现 Google Play 应用静默安装功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12281308/

相关文章:

android - 谷歌地图实用程序中集群的背景渲染

Android - 覆盖 Small、Medium、Large 的 textAppearance

Android - 永远不会调用 OnDraw() 方法

android - 选项卡式操作栏内的 fragment 导航

Chrome 72 更新后 Android Cordova 应用渲染缓慢

android - "getApplicationLabel"和 "loadLabel"有什么区别?

java - 使用受密码保护的网站的 Jsoup 获取 HTML 源代码

java - android zxing Intent 集成器

android - 在 ListView 中单击的项目的索引

java - 将数据库复制到 SD 卡(如果存在)