Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6317f684 authored by Vinod Krishnan's avatar Vinod Krishnan
Browse files

Wear Cleanup: Removing implicit intent & API change

- Remove a way to implicitly call Wear install service
- Also make the Service take in the package as the data, just like the
activities in PackageInstaller

Change-Id: I0c4c9cebbb7396e025cab81eed835ab1a941ca01
parent 5a86422a
Loading
Loading
Loading
Loading
+1 −9
Original line number Diff line number Diff line
@@ -125,15 +125,7 @@
        <!-- Wearable Components -->
        <service android:name=".wear.WearPackageInstallerService"
                 android:permission="com.google.android.permission.INSTALL_WEARABLE_PACKAGES"
                 android:exported="true">
            <intent-filter>
                <action android:name="com.android.packageinstaller.wear.INSTALL_PACKAGE"/>
                <data android:scheme="content" android:mimeType="vnd.android.cursor.item/*"/>
            </intent-filter>
            <intent-filter>
                <action android:name="com.android.packageinstaller.wear.UNINSTALL_PACKAGE"/>
            </intent-filter>
        </service>
                 android:exported="true"/>

        <provider android:name=".wear.WearPackageIconProvider"
                  android:authorities="com.google.android.packageinstaller.wear.provider"
+8 −6
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.os.Bundle;
 * installing/uninstalling.
 */
public class WearPackageArgs {
    private static final String KEY_PACKAGE_NAME =
            "com.google.android.clockwork.EXTRA_PACKAGE_NAME";
    private static final String KEY_ASSET_URI =
            "com.google.android.clockwork.EXTRA_ASSET_URI";
    private static final String KEY_START_ID =
@@ -45,16 +47,16 @@ public class WearPackageArgs {
            "com.google.android.clockwork.EXTRA_KEY_SHOULD_CHECK_GMS_DEPENDENCY";

    public static String getPackageName(Bundle b) {
        return b.getString(Intent.EXTRA_INSTALLER_PACKAGE_NAME);
        return b.getString(KEY_PACKAGE_NAME);
    }

    public static Uri getAssetUri(Bundle b) {
        return b.getParcelable(KEY_ASSET_URI);
    public static Bundle setPackageName(Bundle b, String packageName) {
        b.putString(KEY_PACKAGE_NAME, packageName);
        return b;
    }

    public static Bundle setAssetUri(Bundle b, Uri assetUri) {
        b.putParcelable(KEY_ASSET_URI, assetUri);
        return b;
    public static Uri getAssetUri(Bundle b) {
        return b.getParcelable(KEY_ASSET_URI);
    }

    public static Uri getPermUri(Bundle b) {
+43 −18
Original line number Diff line number Diff line
@@ -66,13 +66,18 @@ import java.util.Set;
 *
 *  Install Action example:
 *  adb shell am startservice -a com.android.packageinstaller.wear.INSTALL_PACKAGE \
 *     -t vnd.android.cursor.item/wearable_apk \
 *     -d content://com.google.android.clockwork.home.provider/host/com.google.android.wearable.app/wearable/com.google.android.gms/apk \
 *     -d package://com.google.android.gms \
 *     --eu com.google.android.clockwork.EXTRA_ASSET_URI content://com.google.android.clockwork.home.provider/host/com.google.android.wearable.app/wearable/com.google.android.gms/apk \
 *     --es android.intent.extra.INSTALLER_PACKAGE_NAME com.google.android.gms \
 *     --ez com.google.android.clockwork.EXTRA_CHECK_PERMS false \
 *     --eu com.google.android.clockwork.EXTRA_PERM_URI content://com.google.android.clockwork.home.provider/host/com.google.android.wearable.app/permissions \
 *     com.android.packageinstaller/com.android.packageinstaller.wear.WearPackageInstallerService
 *
 *  Uninstall Action example:
 *  adb shell am startservice -a com.android.packageinstaller.wear.UNINSTALL_PACKAGE \
 *     -d package://com.google.android.gms \
 *     com.android.packageinstaller/com.android.packageinstaller.wear.WearPackageInstallerService
 *
 *  Retry GMS:
 *  adb shell am startservice -a com.android.packageinstaller.wear.RETRY_GMS \
 *     com.android.packageinstaller/com.android.packageinstaller.wear.WearPackageInstallerService
@@ -141,22 +146,43 @@ public class WearPackageInstallerService extends Service {
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (!DeviceUtils.isWear(this)) {
            Log.w(TAG, "Not running on wearable");
            Log.w(TAG, "Not running on wearable.");
            return START_NOT_STICKY;
        }
        PowerManager.WakeLock lock = getLock(this.getApplicationContext());
        if (!lock.isHeld()) {
            lock.acquire();

        if (intent == null) {
            Log.w(TAG, "Got null intent.");
            return START_NOT_STICKY;
        }

        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "Got install/uninstall request " + intent);
        }
        if (intent != null) {

        Uri packageUri = intent.getData();
        if (packageUri == null) {
            Log.e(TAG, "No package URI in intent");
            return START_NOT_STICKY;
        }
        final String packageName = WearPackageUtil.getSanitizedPackageName(packageUri);
        if (packageName == null) {
            Log.e(TAG, "Invalid package name in URI (expected package:<pkgName>): " + packageUri);
            return START_NOT_STICKY;
        }

        PowerManager.WakeLock lock = getLock(this.getApplicationContext());
        if (!lock.isHeld()) {
            lock.acquire();
        }

        Bundle intentBundle = intent.getExtras();
        if (intentBundle == null) {
            intentBundle = new Bundle();
        }
        WearPackageArgs.setStartId(intentBundle, startId);
        WearPackageArgs.setPackageName(intentBundle, packageName);
        if (Intent.ACTION_INSTALL_PACKAGE.equals(intent.getAction())) {
                final Message msg = mServiceHandler.obtainMessage(START_INSTALL);
                WearPackageArgs.setAssetUri(intentBundle, intent.getData());
            Message msg = mServiceHandler.obtainMessage(START_INSTALL);
            msg.setData(intentBundle);
            mServiceHandler.sendMessage(msg);
        } else if (Intent.ACTION_UNINSTALL_PACKAGE.equals(intent.getAction())) {
@@ -164,7 +190,6 @@ public class WearPackageInstallerService extends Service {
            msg.setData(intentBundle);
            mServiceHandler.sendMessage(msg);
        }
        }
        return START_NOT_STICKY;
    }

+13 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageParser;
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import android.system.ErrnoException;
import android.system.Os;
@@ -164,4 +165,16 @@ public class WearPackageUtil {
                + " for " + wearablePackageName);
        context.startService(newIntent);
    }

    /**
     * @return com.google.com from expected formats like
     * Uri: package:com.google.com, package:/com.google.com, package://com.google.com
     */
    public static String getSanitizedPackageName(Uri packageUri) {
        String packageName = packageUri.getEncodedSchemeSpecificPart();
        if (packageName != null) {
            return packageName.replaceAll("^/+", "");
        }
        return packageName;
    }
}