FileDocCategorySizeDatePackage
LocationBlacklist.javaAPI DocAndroid 5.1 API4976Thu Mar 12 22:22:42 GMT 2015com.android.server.location

LocationBlacklist

public final class LocationBlacklist extends android.database.ContentObserver
Allows applications to be blacklisted from location updates at run-time. This is a silent blacklist. Applications can still call Location Manager API's, but they just won't receive any locations.

Fields Summary
private static final String
TAG
private static final boolean
D
private static final String
BLACKLIST_CONFIG_NAME
private static final String
WHITELIST_CONFIG_NAME
private final android.content.Context
mContext
private final Object
mLock
private String[]
mWhitelist
private String[]
mBlacklist
private int
mCurrentUserId
Constructors Summary
public LocationBlacklist(android.content.Context context, android.os.Handler handler)

    
         
        super(handler);
        mContext = context;
    
Methods Summary
public voiddump(java.io.PrintWriter pw)

        pw.println("mWhitelist=" + Arrays.toString(mWhitelist) + " mBlacklist=" +
                Arrays.toString(mBlacklist));
    
private java.lang.String[]getStringArrayLocked(java.lang.String key)

        String flatString;
        synchronized(mLock) {
            flatString = Settings.Secure.getStringForUser(mContext.getContentResolver(), key,
                    mCurrentUserId);
        }
        if (flatString == null) {
            return new String[0];
        }
        String[] splitStrings = flatString.split(",");
        ArrayList<String> result = new ArrayList<String>();
        for (String pkg : splitStrings) {
            pkg = pkg.trim();
            if (pkg.isEmpty()) {
                continue;
            }
            result.add(pkg);
        }
        return result.toArray(new String[result.size()]);
    
private booleaninWhitelist(java.lang.String pkg)
Return true if any of packages are in whitelist

        synchronized (mLock) {
            for (String white : mWhitelist) {
                if (pkg.startsWith(white)) return true;
            }
        }
        return false;
    
public voidinit()

        mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(
                BLACKLIST_CONFIG_NAME), false, this, UserHandle.USER_ALL);
//        mContext.getContentResolver().registerContentObserver(Settings.Secure.getUriFor(
//                WHITELIST_CONFIG_NAME), false, this, UserHandle.USER_ALL);
        reloadBlacklist();
    
public booleanisBlacklisted(java.lang.String packageName)
Return true if in blacklist (package name matches blacklist, and does not match whitelist)

        synchronized (mLock) {
            for (String black : mBlacklist) {
                if (packageName.startsWith(black)) {
                    if (inWhitelist(packageName)) {
                        continue;
                    } else {
                        if (D) Log.d(TAG, "dropping location (blacklisted): "
                                + packageName + " matches " + black);
                        return true;
                    }
                }
            }
        }
        return false;
    
public voidonChange(boolean selfChange)

        reloadBlacklist();
    
private voidreloadBlacklist()

        synchronized (mLock) {
            reloadBlacklistLocked();
        }
    
private voidreloadBlacklistLocked()

        mWhitelist = getStringArrayLocked(WHITELIST_CONFIG_NAME);
        if (D) Slog.d(TAG, "whitelist: " + Arrays.toString(mWhitelist));
        mBlacklist = getStringArrayLocked(BLACKLIST_CONFIG_NAME);
        if (D) Slog.d(TAG, "blacklist: " + Arrays.toString(mBlacklist));
    
public voidswitchUser(int userId)

        synchronized(mLock) {
            mCurrentUserId = userId;
            reloadBlacklistLocked();
        }