1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
| package aa;
import android.app.AppOpsManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.net.Uri; import android.os.UserHandle; import android.text.TextUtils; import java.util.ArrayList; import java.util.Iterator; import java.util.concurrent.ConcurrentHashMap;
public class f implements AppOpsManager.OnOpChangedListener {
private static final f f193g = new f();
private boolean f194a;
private Context f196c;
private AppOpsManager f198e;
private final ConcurrentHashMap<String, Integer> f195b = new ConcurrentHashMap<>();
private ArrayList<PackageManager.OnPermissionsChangedListener> f197d = new ArrayList<>();
private final BroadcastReceiver f199f = new a();
class a extends BroadcastReceiver { a() { }
@Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Uri data = intent.getData(); if (data == null) { return; } String schemeSpecificPart = data.getSchemeSpecificPart(); if ("android.intent.action.PACKAGE_REMOVED".equals(action) && !intent.getBooleanExtra("android.intent.extra.REPLACING", false)) { f.this.f195b.remove(schemeSpecificPart); } } }
private f() { }
public static f c() { return f193g; }
private int f(String str) { try { return this.f196c.getPackageManager().getPackageUidAsUser(str, UserHandle.myUserId()); } catch (PackageManager.NameNotFoundException e10) { y7.a.f("AccelerationSettingsManger", "getUid NameNotFoundException = " + e10.getMessage()); return -1; } }
private synchronized void i(int i10) { Iterator<PackageManager.OnPermissionsChangedListener> it = this.f197d.iterator(); while (it.hasNext()) { it.next().onPermissionsChanged(i10); } }
public synchronized void b(PackageManager.OnPermissionsChangedListener onPermissionsChangedListener) { if (!this.f197d.contains(onPermissionsChangedListener)) { this.f197d.add(onPermissionsChangedListener); } }
public void d(Context context) { ApplicationInfo applicationInfo; this.f195b.clear(); for (PackageInfo packageInfo : context.getPackageManager().getInstalledPackagesAsUser(0, context.getUserId())) { if (packageInfo != null && (applicationInfo = packageInfo.applicationInfo) != null) { int i10 = applicationInfo.uid; boolean isSystemApp = applicationInfo.isSystemApp(); if (i10 >= 10000 && !isSystemApp) { String str = packageInfo.packageName; this.f195b.put(str, Integer.valueOf(this.f198e.unsafeCheckOpRawNoThrow(10002, i10, str))); } } } }
public int e(String str) { if (f(str) < 0) { return 3; } Integer num = this.f195b.get(str); if (num == null) { num = Integer.valueOf(this.f198e.unsafeCheckOpRawNoThrow(10002, f(str), str)); this.f195b.put(str, num); } return num.intValue(); }
public void g(Context context) { this.f196c = context; boolean C = n.C(context); this.f194a = C; if (C) { this.f198e = (AppOpsManager) context.getSystemService("appops"); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("android.intent.action.PACKAGE_REMOVED"); intentFilter.addDataScheme("package"); this.f196c.registerReceiver(this.f199f, intentFilter, 2); d(context); this.f198e.startWatchingMode(10002, (String) null, this); } }
public boolean h() { return this.f194a; }
public void j(String str) { try { ApplicationInfo applicationInfo = this.f196c.getPackageManager().getPackageInfo(str, 0).applicationInfo; if (applicationInfo != null) { i(applicationInfo.uid); } } catch (PackageManager.NameNotFoundException e10) { y7.a.f("AccelerationSettingsManger", "notifyPermissionsChanged NameNotFoundException = " + e10.getMessage()); } }
public synchronized void k(PackageManager.OnPermissionsChangedListener onPermissionsChangedListener) { this.f197d.remove(onPermissionsChangedListener); }
public void l(String str, int i10) { m(str, i10, true, true); }
public void m(String str, int i10, boolean z10, boolean z11) { if (!TextUtils.isEmpty(str) && f(str) >= 0) { if (z11) { j(str); } Integer num = this.f195b.get(str); if (num == null || num.intValue() != i10) { this.f195b.put(str, Integer.valueOf(i10)); if (z10) { this.f198e.setUidMode(10002, f(str), i10); this.f198e.setMode(10002, f(str), str, i10); n.h(this.f196c, str); y7.a.h("AccelerationSettingsManger", "set state: uid=" + f(str) + ", pkg=" + str + ", userId=" + UserHandle.myUserId() + ", state=" + i10); } } } }
@Override public void onOpChanged(String str, String str2) { int f10 = f(str2); if (f10 < 0) { return; } int unsafeCheckOpRawNoThrow = this.f198e.unsafeCheckOpRawNoThrow(10002, f10, str2); if (unsafeCheckOpRawNoThrow != e(str2)) { m(str2, unsafeCheckOpRawNoThrow, false, true); } y7.a.d("AccelerationSettingsManger", "onOpChanged: pkg=" + str2 + ", uid=" + f10 + ", userId=" + UserHandle.myUserId()); } }
|