| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.compat; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.app.PropertyInvalidatedCache; |
| 21 |
import android.content.Context; |
| 22 |
import android.os.Binder; |
| 23 |
import android.os.RemoteException; |
| 24 |
import android.os.ServiceManager; |
| 25 |
|
| 26 |
import com.android.internal.compat.IPlatformCompat; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public final class ChangeIdStateCache |
| 33 |
extends PropertyInvalidatedCache<ChangeIdStateQuery, Boolean> { |
| 34 |
private static final String CACHE_KEY = "cache_key.is_compat_change_enabled"; |
| 35 |
private static final int MAX_ENTRIES = 20; |
| 36 |
private static boolean sDisabled = false; |
| 37 |
private volatile IPlatformCompat mPlatformCompat; |
| 38 |
|
| 39 |
|
| 40 |
public ChangeIdStateCache() { |
| 41 |
super(MAX_ENTRIES, CACHE_KEY); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public static void disable() { |
| 51 |
sDisabled = true; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public static void invalidate() { |
| 61 |
if (!sDisabled) { |
| 62 |
PropertyInvalidatedCache.invalidateCache(CACHE_KEY); |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
@NonNull |
| 67 |
IPlatformCompat getPlatformCompatService() { |
| 68 |
IPlatformCompat platformCompat = mPlatformCompat; |
| 69 |
if (platformCompat == null) { |
| 70 |
synchronized (this) { |
| 71 |
platformCompat = mPlatformCompat; |
| 72 |
if (platformCompat == null) { |
| 73 |
platformCompat = IPlatformCompat.Stub.asInterface( |
| 74 |
ServiceManager.getService(Context.PLATFORM_COMPAT_SERVICE)); |
| 75 |
if (platformCompat == null) { |
| 76 |
throw new RuntimeException( |
| 77 |
"Could not get PlatformCompatService instance!"); |
| 78 |
} |
| 79 |
mPlatformCompat = platformCompat; |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
return platformCompat; |
| 84 |
} |
| 85 |
|
| 86 |
@Override |
| 87 |
public Boolean recompute(ChangeIdStateQuery query) { |
| 88 |
final long token = Binder.clearCallingIdentity(); |
| 89 |
try { |
| 90 |
if (query.type == ChangeIdStateQuery.QUERY_BY_PACKAGE_NAME) { |
| 91 |
return getPlatformCompatService().isChangeEnabledByPackageName(query.changeId, |
| 92 |
query.packageName, |
| 93 |
query.userId); |
| 94 |
} else if (query.type == ChangeIdStateQuery.QUERY_BY_UID) { |
| 95 |
return getPlatformCompatService().isChangeEnabledByUid(query.changeId, query.uid); |
| 96 |
} else { |
| 97 |
throw new IllegalArgumentException("Invalid query type: " + query.type); |
| 98 |
} |
| 99 |
} catch (RemoteException e) { |
| 100 |
e.rethrowFromSystemServer(); |
| 101 |
} finally { |
| 102 |
Binder.restoreCallingIdentity(token); |
| 103 |
} |
| 104 |
throw new IllegalStateException("Could not recompute value!"); |
| 105 |
} |
| 106 |
} |