Method to check for privleged permissions via IPC
This commit is contained in:
		
							parent
							
								
									85c8e7035d
								
							
						
					
					
						commit
						976d06ea1a
					
				@ -19,7 +19,10 @@
 | 
			
		||||
 | 
			
		||||
package org.fdroid.fdroid.privileged;
 | 
			
		||||
 | 
			
		||||
import android.*;
 | 
			
		||||
import android.Manifest;
 | 
			
		||||
import android.app.Service;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.content.Intent;
 | 
			
		||||
import android.content.pm.IPackageDeleteObserver;
 | 
			
		||||
import android.content.pm.IPackageInstallObserver;
 | 
			
		||||
@ -41,6 +44,17 @@ public class PrivilegedService extends Service {
 | 
			
		||||
    private Method mInstallMethod;
 | 
			
		||||
    private Method mDeleteMethod;
 | 
			
		||||
 | 
			
		||||
    private boolean hasPrivilegedPermissionsImpl() {
 | 
			
		||||
        boolean hasInstallPermission =
 | 
			
		||||
                (getPackageManager().checkPermission(Manifest.permission.INSTALL_PACKAGES, getPackageName())
 | 
			
		||||
                        == PackageManager.PERMISSION_GRANTED);
 | 
			
		||||
        boolean hasDeletePermission =
 | 
			
		||||
                (getPackageManager().checkPermission(Manifest.permission.DELETE_PACKAGES, getPackageName())
 | 
			
		||||
                        == PackageManager.PERMISSION_GRANTED);
 | 
			
		||||
 | 
			
		||||
        return (hasInstallPermission && hasDeletePermission);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void installPackageImpl(Uri packageURI, int flags, String installerPackageName,
 | 
			
		||||
                                    final IPrivilegedCallback callback) {
 | 
			
		||||
 | 
			
		||||
@ -101,6 +115,11 @@ public class PrivilegedService extends Service {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private final IPrivilegedService.Stub mBinder = new IPrivilegedService.Stub() {
 | 
			
		||||
        @Override
 | 
			
		||||
        public boolean hasPrivilegedPermissions() {
 | 
			
		||||
            return hasPrivilegedPermissionsImpl();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @Override
 | 
			
		||||
        public void installPackage(Uri packageURI, int flags, String installerPackageName,
 | 
			
		||||
                                   IPrivilegedCallback callback) {
 | 
			
		||||
 | 
			
		||||
@ -21,13 +21,13 @@ package org.fdroid.fdroid.privileged;
 | 
			
		||||
 | 
			
		||||
import org.fdroid.fdroid.privileged.IPrivilegedCallback;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Asynchronous (oneway) IPC calls!
 | 
			
		||||
 */
 | 
			
		||||
oneway interface IPrivilegedService {
 | 
			
		||||
interface IPrivilegedService {
 | 
			
		||||
 | 
			
		||||
    boolean hasPrivilegedPermissions();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Docs based on PackageManager.installPackage()
 | 
			
		||||
     * - Docs based on PackageManager.installPackage()
 | 
			
		||||
     * - Asynchronous (oneway) IPC calls!
 | 
			
		||||
     *
 | 
			
		||||
     * Install a package. Since this may take a little while, the result will
 | 
			
		||||
     * be posted back to the given callback. An installation will fail if the
 | 
			
		||||
@ -43,12 +43,13 @@ oneway interface IPrivilegedService {
 | 
			
		||||
     * @param callback An callback to get notified when the package installation is
 | 
			
		||||
     * complete.
 | 
			
		||||
     */
 | 
			
		||||
    void installPackage(in Uri packageURI, in int flags, in String installerPackageName,
 | 
			
		||||
    oneway void installPackage(in Uri packageURI, in int flags, in String installerPackageName,
 | 
			
		||||
                        in IPrivilegedCallback callback);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Docs based on PackageManager.deletePackage()
 | 
			
		||||
     * - Docs based on PackageManager.deletePackage()
 | 
			
		||||
     * - Asynchronous (oneway) IPC calls!
 | 
			
		||||
     *
 | 
			
		||||
     * Attempts to delete a package.  Since this may take a little while, the result will
 | 
			
		||||
     * be posted back to the given observer.  A deletion will fail if the
 | 
			
		||||
@ -60,6 +61,6 @@ oneway interface IPrivilegedService {
 | 
			
		||||
     * @param callback An callback to get notified when the package deletion is
 | 
			
		||||
     * complete.
 | 
			
		||||
     */
 | 
			
		||||
    void deletePackage(in String packageName, in int flags, in IPrivilegedCallback callback);
 | 
			
		||||
    oneway void deletePackage(in String packageName, in int flags, in IPrivilegedCallback callback);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user