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

Commit 39fb7fd7 authored by Benjamin Franz's avatar Benjamin Franz
Browse files

Allow silent package install for device owner.

Allow the device owner to silently install and remove packages using the
PackageInstaller APIs. Show notifications to the user after the
installation / deletion was successful.

Bug: 19422461
Change-Id: I0506e18c510efd9d04c4aea9b60a37456e689615
parent 80ac6036
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -1385,7 +1385,8 @@ public final class Pm {
        }
        }


        final LocalIntentReceiver receiver = new LocalIntentReceiver();
        final LocalIntentReceiver receiver = new LocalIntentReceiver();
        mInstaller.uninstall(pkg, flags, receiver.getIntentSender(), userId);
        mInstaller.uninstall(pkg, null /* callerPackageName */, flags,
                receiver.getIntentSender(), userId);


        final Intent result = receiver.getResult();
        final Intent result = receiver.getResult();
        final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
        final int status = result.getIntExtra(PackageInstaller.EXTRA_STATUS,
+2 −1
Original line number Original line Diff line number Diff line
@@ -44,7 +44,8 @@ interface IPackageInstaller {
    void registerCallback(IPackageInstallerCallback callback, int userId);
    void registerCallback(IPackageInstallerCallback callback, int userId);
    void unregisterCallback(IPackageInstallerCallback callback);
    void unregisterCallback(IPackageInstallerCallback callback);


    void uninstall(String packageName, int flags, in IntentSender statusReceiver, int userId);
    void uninstall(String packageName, String callerPackageName, int flags,
            in IntentSender statusReceiver, int userId);


    void setPermissionsResult(int sessionId, boolean accepted);
    void setPermissionsResult(int sessionId, boolean accepted);
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -423,7 +423,7 @@ public class PackageInstaller {
     */
     */
    public void uninstall(@NonNull String packageName, @NonNull IntentSender statusReceiver) {
    public void uninstall(@NonNull String packageName, @NonNull IntentSender statusReceiver) {
        try {
        try {
            mInstaller.uninstall(packageName, 0, statusReceiver, mUserId);
            mInstaller.uninstall(packageName, mInstallerPackageName, 0, statusReceiver, mUserId);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowAsRuntimeException();
            throw e.rethrowAsRuntimeException();
        }
        }
+39 −0
Original line number Original line Diff line number Diff line
@@ -17,10 +17,13 @@
package com.android.internal.util;
package com.android.internal.util;


import android.graphics.Bitmap;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;


/**
/**
 * Utility class for image analysis and processing.
 * Utility class for image analysis and processing.
@@ -117,4 +120,40 @@ public class ImageUtils {
                && Math.abs(r - b) < TOLERANCE
                && Math.abs(r - b) < TOLERANCE
                && Math.abs(g - b) < TOLERANCE;
                && Math.abs(g - b) < TOLERANCE;
    }
    }

    /**
     * Convert a drawable to a bitmap, scaled to fit within maxWidth and maxHeight.
     */
    public static Bitmap buildScaledBitmap(Drawable drawable, int maxWidth,
            int maxHeight) {
        if (drawable == null) {
            return null;
        }
        int originalWidth = drawable.getIntrinsicWidth();
        int originalHeight = drawable.getIntrinsicHeight();

        if ((originalWidth <= maxWidth) && (originalHeight <= maxHeight) &&
                (drawable instanceof BitmapDrawable)) {
            return ((BitmapDrawable) drawable).getBitmap();
        }
        if (originalHeight <= 0 || originalWidth <= 0) {
            return null;
        }

        // create a new bitmap, scaling down to fit the max dimensions of
        // a large notification icon if necessary
        float ratio = Math.min((float) maxWidth / (float) originalWidth,
                (float) maxHeight / (float) originalHeight);
        ratio = Math.min(1.0f, ratio);
        int scaledWidth = (int) (ratio * originalWidth);
        int scaledHeight = (int) (ratio * originalHeight);
        Bitmap result = Bitmap.createBitmap(scaledWidth, scaledHeight, Config.ARGB_8888);

        // and paint our app bitmap on it
        Canvas canvas = new Canvas(result);
        drawable.setBounds(0, 0, scaledWidth, scaledHeight);
        drawable.draw(canvas);

        return result;
    }
}
}
+27 −0
Original line number Original line Diff line number Diff line
<!--
Copyright (C) 2015 The Android Open Source Project

   Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24.0dp"
        android:height="24.0dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0">
    <path
        android:pathData="M0 0h24v24H0z"
        android:fillColor="#00000000"/>
    <path
        android:fillColor="#FF000000"
        android:pathData="M12.0,2.0C6.48,2.0 2.0,6.48 2.0,12.0s4.48,10.0 10.0,10.0 10.0,-4.48 10.0,-10.0S17.52,2.0 12.0,2.0zm-2.0,15.0l-5.0,-5.0 1.41,-1.41L10.0,14.17l7.59,-7.59L19.0,8.0l-9.0,9.0z"/>
</vector>
Loading