Search in sources :

Example 81 with ProviderInfo

use of android.content.pm.ProviderInfo in project storio by pushtorefresh.

the class IntegrationTest method setUp.

@Before
public void setUp() {
    contentResolver = RuntimeEnvironment.application.getContentResolver();
    storIOContentResolver = createStoreIOContentResolver().build();
    ContentProviderController<IntegrationContentProvider> controller = Robolectric.buildContentProvider(IntegrationContentProvider.class);
    ProviderInfo providerInfo = new ProviderInfo();
    providerInfo.authority = IntegrationContentProvider.AUTHORITY;
    controller.create(providerInfo);
}
Also used : ProviderInfo(android.content.pm.ProviderInfo) Before(org.junit.Before)

Example 82 with ProviderInfo

use of android.content.pm.ProviderInfo in project cornerstone by Onskreen.

the class ActivityManagerService method installSystemProviders.

public static final void installSystemProviders() {
    List<ProviderInfo> providers;
    synchronized (mSelf) {
        ProcessRecord app = mSelf.mProcessNames.get("system", Process.SYSTEM_UID);
        providers = mSelf.generateApplicationProvidersLocked(app);
        if (providers != null) {
            for (int i = providers.size() - 1; i >= 0; i--) {
                ProviderInfo pi = (ProviderInfo) providers.get(i);
                if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
                    Slog.w(TAG, "Not installing system proc provider " + pi.name + ": not system .apk");
                    providers.remove(i);
                }
            }
        }
    }
    if (providers != null) {
        mSystemThread.installSystemProviders(providers);
    }
    mSelf.mCoreSettingsObserver = new CoreSettingsObserver(mSelf);
    mSelf.mUsageStatsService.monitorPackages();
}
Also used : ProviderInfo(android.content.pm.ProviderInfo)

Example 83 with ProviderInfo

use of android.content.pm.ProviderInfo in project cornerstone by Onskreen.

the class ActivityManagerService method checkGrantUriPermissionLocked.

/**
 * Check if the targetPkg can be granted permission to access uri by
 * the callingUid using the given modeFlags.  Throws a security exception
 * if callingUid is not allowed to do this.  Returns the uid of the target
 * if the URI permission grant should be performed; returns -1 if it is not
 * needed (for example targetPkg already has permission to access the URI).
 * If you already know the uid of the target, you can supply it in
 * lastTargetUid else set that to -1.
 */
int checkGrantUriPermissionLocked(int callingUid, String targetPkg, Uri uri, int modeFlags, int lastTargetUid) {
    modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    if (modeFlags == 0) {
        return -1;
    }
    if (targetPkg != null) {
        if (DEBUG_URI_PERMISSION)
            Slog.v(TAG, "Checking grant " + targetPkg + " permission to " + uri);
    }
    final IPackageManager pm = AppGlobals.getPackageManager();
    // If this is not a content: uri, we can't do anything with it.
    if (!ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
        if (DEBUG_URI_PERMISSION)
            Slog.v(TAG, "Can't grant URI permission for non-content URI: " + uri);
        return -1;
    }
    String name = uri.getAuthority();
    ProviderInfo pi = null;
    ContentProviderRecord cpr = mProviderMap.getProviderByName(name, UserId.getUserId(callingUid));
    if (cpr != null) {
        pi = cpr.info;
    } else {
        try {
            pi = pm.resolveContentProvider(name, PackageManager.GET_URI_PERMISSION_PATTERNS, UserId.getUserId(callingUid));
        } catch (RemoteException ex) {
        }
    }
    if (pi == null) {
        Slog.w(TAG, "No content provider found for permission check: " + uri.toSafeString());
        return -1;
    }
    int targetUid = lastTargetUid;
    if (targetUid < 0 && targetPkg != null) {
        try {
            targetUid = pm.getPackageUid(targetPkg, UserId.getUserId(callingUid));
            if (targetUid < 0) {
                if (DEBUG_URI_PERMISSION)
                    Slog.v(TAG, "Can't grant URI permission no uid for: " + targetPkg);
                return -1;
            }
        } catch (RemoteException ex) {
            return -1;
        }
    }
    if (targetUid >= 0) {
        // First...  does the target actually need this permission?
        if (checkHoldingPermissionsLocked(pm, pi, uri, targetUid, modeFlags)) {
            // No need to grant the target this permission.
            if (DEBUG_URI_PERMISSION)
                Slog.v(TAG, "Target " + targetPkg + " already has full permission to " + uri);
            return -1;
        }
    } else {
        // First...  there is no target package, so can anyone access it?
        boolean allowed = pi.exported;
        if ((modeFlags & Intent.FLAG_GRANT_READ_URI_PERMISSION) != 0) {
            if (pi.readPermission != null) {
                allowed = false;
            }
        }
        if ((modeFlags & Intent.FLAG_GRANT_WRITE_URI_PERMISSION) != 0) {
            if (pi.writePermission != null) {
                allowed = false;
            }
        }
        if (allowed) {
            return -1;
        }
    }
    // Second...  is the provider allowing granting of URI permissions?
    if (!pi.grantUriPermissions) {
        throw new SecurityException("Provider " + pi.packageName + "/" + pi.name + " does not allow granting of Uri permissions (uri " + uri + ")");
    }
    if (pi.uriPermissionPatterns != null) {
        final int N = pi.uriPermissionPatterns.length;
        boolean allowed = false;
        for (int i = 0; i < N; i++) {
            if (pi.uriPermissionPatterns[i] != null && pi.uriPermissionPatterns[i].match(uri.getPath())) {
                allowed = true;
                break;
            }
        }
        if (!allowed) {
            throw new SecurityException("Provider " + pi.packageName + "/" + pi.name + " does not allow granting of permission to path of Uri " + uri);
        }
    }
    // this uri?
    if (callingUid != Process.myUid()) {
        if (!checkHoldingPermissionsLocked(pm, pi, uri, callingUid, modeFlags)) {
            if (!checkUriPermissionLocked(uri, callingUid, modeFlags)) {
                throw new SecurityException("Uid " + callingUid + " does not have permission to uri " + uri);
            }
        }
    }
    return targetUid;
}
Also used : IPackageManager(android.content.pm.IPackageManager) ProviderInfo(android.content.pm.ProviderInfo) RemoteException(android.os.RemoteException)

Example 84 with ProviderInfo

use of android.content.pm.ProviderInfo in project cornerstone by Onskreen.

the class ActivityManagerService method revokeUriPermission.

public void revokeUriPermission(IApplicationThread caller, Uri uri, int modeFlags) {
    enforceNotIsolatedCaller("revokeUriPermission");
    synchronized (this) {
        final ProcessRecord r = getRecordForAppLocked(caller);
        if (r == null) {
            throw new SecurityException("Unable to find app for caller " + caller + " when revoking permission to uri " + uri);
        }
        if (uri == null) {
            Slog.w(TAG, "revokeUriPermission: null uri");
            return;
        }
        modeFlags &= (Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
        if (modeFlags == 0) {
            return;
        }
        final IPackageManager pm = AppGlobals.getPackageManager();
        final String authority = uri.getAuthority();
        ProviderInfo pi = null;
        ContentProviderRecord cpr = mProviderMap.getProviderByName(authority, r.userId);
        if (cpr != null) {
            pi = cpr.info;
        } else {
            try {
                pi = pm.resolveContentProvider(authority, PackageManager.GET_URI_PERMISSION_PATTERNS, r.userId);
            } catch (RemoteException ex) {
            }
        }
        if (pi == null) {
            Slog.w(TAG, "No content provider found for permission revoke: " + uri.toSafeString());
            return;
        }
        revokeUriPermissionLocked(r.uid, uri, modeFlags);
    }
}
Also used : IPackageManager(android.content.pm.IPackageManager) ProviderInfo(android.content.pm.ProviderInfo) RemoteException(android.os.RemoteException)

Example 85 with ProviderInfo

use of android.content.pm.ProviderInfo in project tray by grandcentrix.

the class TrayContractTest method testGenerateInternalContentUri_WithCorrectProvider_ShouldWork.

public void testGenerateInternalContentUri_WithCorrectProvider_ShouldWork() throws Exception {
    final List<ProviderInfo> mockProviders = new ArrayList<>();
    ProviderInfo wrongInfo = new ProviderInfo();
    wrongInfo.authority = "wrong";
    wrongInfo.name = "wrong";
    mockProviders.add(wrongInfo);
    ProviderInfo info = new ProviderInfo();
    info.authority = "my.custom.authority";
    info.name = TrayContentProvider.class.getName();
    mockProviders.add(info);
    getProviderMockContext().setProviderInfos(mockProviders);
    TrayContract.generateInternalContentUri(getProviderMockContext());
    assertEquals("my.custom.authority", TrayContract.sAuthority);
}
Also used : ProviderInfo(android.content.pm.ProviderInfo) ArrayList(java.util.ArrayList)

Aggregations

ProviderInfo (android.content.pm.ProviderInfo)200 ComponentName (android.content.ComponentName)43 RemoteException (android.os.RemoteException)36 ArrayList (java.util.ArrayList)33 PackageManager (android.content.pm.PackageManager)27 ResolveInfo (android.content.pm.ResolveInfo)23 ApplicationInfo (android.content.pm.ApplicationInfo)22 ServiceInfo (android.content.pm.ServiceInfo)16 Point (android.graphics.Point)16 VPackage (com.lody.virtual.server.pm.parser.VPackage)15 PackageInfo (android.content.pm.PackageInfo)14 Map (java.util.Map)14 Test (org.junit.Test)14 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)13 Uri (android.net.Uri)13 File (java.io.File)13 IPackageManager (android.content.pm.IPackageManager)12 ActivityInfo (android.content.pm.ActivityInfo)10 Before (org.junit.Before)10 Intent (android.content.Intent)8