Search in sources :

Example 1 with IPrivilegedCallback

use of org.fdroid.fdroid.privileged.IPrivilegedCallback in project fdroidclient by f-droid.

the class PrivilegedInstaller method installPackageInternal.

@Override
protected void installPackageInternal(final Uri localApkUri, final Uri canonicalUri) {
    ServiceConnection mServiceConnection = new ServiceConnection() {

        public void onServiceConnected(ComponentName name, IBinder service) {
            IPrivilegedService privService = IPrivilegedService.Stub.asInterface(service);
            IPrivilegedCallback callback = new IPrivilegedCallback.Stub() {

                @Override
                public void handleResult(String packageName, int returnCode) throws RemoteException {
                    if (returnCode == INSTALL_SUCCEEDED) {
                        sendBroadcastInstall(canonicalUri, ACTION_INSTALL_COMPLETE);
                    } else {
                        sendBroadcastInstall(canonicalUri, ACTION_INSTALL_INTERRUPTED, "Error " + returnCode + ": " + INSTALL_RETURN_CODES.get(returnCode));
                    }
                }
            };
            try {
                boolean hasPermissions = privService.hasPrivilegedPermissions();
                if (!hasPermissions) {
                    sendBroadcastInstall(canonicalUri, ACTION_INSTALL_INTERRUPTED, context.getString(R.string.system_install_denied_permissions));
                    return;
                }
                privService.installPackage(localApkUri, ACTION_INSTALL_REPLACE_EXISTING, null, callback);
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException", e);
                sendBroadcastInstall(canonicalUri, ACTION_INSTALL_INTERRUPTED, "connecting to privileged service failed");
            }
        }

        public void onServiceDisconnected(ComponentName name) {
        }
    };
    Intent serviceIntent = new Intent(PRIVILEGED_EXTENSION_SERVICE_INTENT);
    serviceIntent.setPackage(PRIVILEGED_EXTENSION_PACKAGE_NAME);
    context.getApplicationContext().bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) ComponentName(android.content.ComponentName) Intent(android.content.Intent) IPrivilegedService(org.fdroid.fdroid.privileged.IPrivilegedService) RemoteException(android.os.RemoteException) IPrivilegedCallback(org.fdroid.fdroid.privileged.IPrivilegedCallback)

Example 2 with IPrivilegedCallback

use of org.fdroid.fdroid.privileged.IPrivilegedCallback in project fdroidclient by f-droid.

the class PrivilegedInstaller method uninstallPackage.

@Override
protected void uninstallPackage() {
    ServiceConnection mServiceConnection = new ServiceConnection() {

        public void onServiceConnected(ComponentName name, IBinder service) {
            IPrivilegedService privService = IPrivilegedService.Stub.asInterface(service);
            IPrivilegedCallback callback = new IPrivilegedCallback.Stub() {

                @Override
                public void handleResult(String packageName, int returnCode) throws RemoteException {
                    if (returnCode == DELETE_SUCCEEDED) {
                        sendBroadcastUninstall(ACTION_UNINSTALL_COMPLETE);
                    } else {
                        sendBroadcastUninstall(ACTION_UNINSTALL_INTERRUPTED, "Error " + returnCode + ": " + UNINSTALL_RETURN_CODES.get(returnCode));
                    }
                }
            };
            try {
                boolean hasPermissions = privService.hasPrivilegedPermissions();
                if (!hasPermissions) {
                    sendBroadcastUninstall(ACTION_UNINSTALL_INTERRUPTED, context.getString(R.string.system_install_denied_permissions));
                    return;
                }
                privService.deletePackage(apk.packageName, 0, callback);
            } catch (RemoteException e) {
                Log.e(TAG, "RemoteException", e);
                sendBroadcastUninstall(ACTION_UNINSTALL_INTERRUPTED, "connecting to privileged service failed");
            }
        }

        public void onServiceDisconnected(ComponentName name) {
        }
    };
    Intent serviceIntent = new Intent(PRIVILEGED_EXTENSION_SERVICE_INTENT);
    serviceIntent.setPackage(PRIVILEGED_EXTENSION_PACKAGE_NAME);
    context.getApplicationContext().bindService(serviceIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
}
Also used : ServiceConnection(android.content.ServiceConnection) IBinder(android.os.IBinder) ComponentName(android.content.ComponentName) Intent(android.content.Intent) IPrivilegedService(org.fdroid.fdroid.privileged.IPrivilegedService) RemoteException(android.os.RemoteException) IPrivilegedCallback(org.fdroid.fdroid.privileged.IPrivilegedCallback)

Aggregations

ComponentName (android.content.ComponentName)2 Intent (android.content.Intent)2 ServiceConnection (android.content.ServiceConnection)2 IBinder (android.os.IBinder)2 RemoteException (android.os.RemoteException)2 IPrivilegedCallback (org.fdroid.fdroid.privileged.IPrivilegedCallback)2 IPrivilegedService (org.fdroid.fdroid.privileged.IPrivilegedService)2