由于未调用onServiceConnected,因此无法在Samsung Galaxy S8和S9上下载OBB

时间:2018-07-04 11:00:12

标签: android service android-service licensing android-lvl

我已将官方Downloader库集成到我的应用程序中,但无法在S8和S9上下载OBB(可以在其他设备上下载OBB)。我在代码中插入了一些调试检查点:

public class LicenseChecker implements ServiceConnection {
...
    public synchronized void checkAccess(LicenseCheckerCallback callback) {
        // If we have a valid recent LICENSED response, we can skip asking
        // Market.
        if (mPolicy.allowAccess()) {
            Log.i(TAG, "Using cached license response");
            callback.allow(Policy.LICENSED);
        } else {
            LicenseValidator validator = new LicenseValidator(mPolicy, new NullDeviceLimiter(),
                    callback, generateNonce(), mPackageName, mVersionCode);

            if (mService == null) {
                Log.i(TAG, "Binding to licensing service.");
                try {
                    Log.d(TAG, "checkAccess 1");

                    Intent serviceIntent = new Intent(new String(Base64.decode("Y29tLmFuZHJvaWQudmVuZGluZy5saWNlbnNpbmcuSUxpY2Vuc2luZ1NlcnZpY2U=")));
                    serviceIntent.setPackage("com.android.vending");

                    Log.d(TAG, "checkAccess 2");

                    boolean bindResult = mContext.bindService(serviceIntent,
                            this, // ServiceConnection.
                            Context.BIND_AUTO_CREATE);

                    Log.d(TAG, "checkAccess 3");

                    if (bindResult) {
                        Log.d(TAG, "checkAccess 4");
                        mPendingChecks.offer(validator);
                        Log.d(TAG, "checkAccess 5");
                    } else {
                        Log.e(TAG, "Could not bind to service.");
                        handleServiceConnectionError(validator);
                    }
                } catch (SecurityException e) {
                    callback.applicationError(LicenseCheckerCallback.ERROR_MISSING_PERMISSION);
                } catch (Base64DecoderException e) {
                    e.printStackTrace();
                }
            } else {
                mPendingChecks.offer(validator);
                Log.d(TAG, "checkAccess 10");
                runChecks();
            }
        }
    }

    private void runChecks() {
        Log.d(TAG, "runChecks");
        LicenseValidator validator;
        while ((validator = mPendingChecks.poll()) != null) {
            try {
                Log.i(TAG, "Calling checkLicense on service for " + validator.getPackageName());
                mService.checkLicense(
                        validator.getNonce(), validator.getPackageName(),
                        new ResultListener(validator));
                mChecksInProgress.add(validator);
            } catch (RemoteException e) {
                Log.w(TAG, "RemoteException in checkLicense call.", e);
                handleServiceConnectionError(validator);
            }
        }
    }
...
    public synchronized void onServiceConnected(ComponentName name, IBinder service) {
        Log.d(TAG, "onServiceConnected");
        mService = ILicensingService.Stub.asInterface(service);
        runChecks();
    }

...

}

可以在Samsung Galaxy S6 OBB上下载,这是控制台日志:

07-04 13:24:32.061 19224-19224/ru.sample.tmp2 I/LicenseChecker: Binding to licensing service.
07-04 13:24:32.061 19224-19224/ru.sample.tmp2 D/LicenseChecker: checkAccess 1
    checkAccess 2
    checkAccess 3
    checkAccess 4
    checkAccess 5
07-04 13:24:32.061 19224-19224/ru.sample.tmp2 E/DownloaderActivity: onDownloadStateChanged
07-04 13:24:32.081 19224-19224/ru.sample.tmp2 D/LicenseChecker: onServiceConnected
    runChecks

但是在Samsung Galaxy S8和S9上,下载挂起,并且我只看到“正在寻找要下载的资源”。

从控制台日志中我看到,绑定到许可服务后的onServiceConnected永远不会被调用(而runChecks也永远不会被调用):

07-04 13:22:15.724 28734-28734/ru.sample.tmp2 I/LicenseChecker: Binding to licensing service.
07-04 13:22:15.724 28734-28734/ru.sample.tmp2 D/LicenseChecker: checkAccess 1
    checkAccess 2
07-04 13:22:15.727 28734-28734/ru.sample.tmp2 D/LicenseChecker: checkAccess 3
    checkAccess 4
    checkAccess 5
07-04 13:22:15.728 28734-28734/ru.sample.tmp2 E/DownloaderActivity: onDownloadStateChanged 

在两个设备上都正确配置了Google帐户。

那么有人可以帮助解决这个问题吗?

0 个答案:

没有答案