• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

frameworks/base


Commit MetaInfo

Revisionb0405c5c1fdd2f24701bc53f54ff7811c4ec22fa (tree)
Time2020-02-12 04:07:54
Authorandroid-build-team Robot <android-build-team-robot@goog...>
Commiterandroid-build-team Robot

Log Message

Merge cherrypicks of [10297641, 10298303, 10298494, 10298514, 10297196, 10298164, 10297642, 10297643, 10296046, 10296047, 10298245, 10298246, 10297197, 10297198, 10298495, 10298496] into qt-qpr2-release

Change-Id: I1f8470eec0bf64e28290002664f6e5a6c8d733dc

Change Summary

Incremental Difference

--- a/core/java/android/content/res/AssetManager.java
+++ b/core/java/android/content/res/AssetManager.java
@@ -1157,8 +1157,11 @@ public final class AssetManager implements AutoCloseable {
11571157 }
11581158 }
11591159
1160- if (mObject != 0) {
1161- nativeDestroy(mObject);
1160+ synchronized (this) {
1161+ if (mObject != 0) {
1162+ nativeDestroy(mObject);
1163+ mObject = 0;
1164+ }
11621165 }
11631166 }
11641167
--- a/core/java/android/os/ExternalVibration.java
+++ b/core/java/android/os/ExternalVibration.java
@@ -157,7 +157,6 @@ public class ExternalVibration implements Parcelable {
157157 out.writeInt(mUid);
158158 out.writeString(mPkg);
159159 writeAudioAttributes(mAttrs, out, flags);
160- out.writeParcelable(mAttrs, flags);
161160 out.writeStrongBinder(mController.asBinder());
162161 out.writeStrongBinder(mToken);
163162 }
--- /dev/null
+++ b/core/tests/coretests/src/android/os/ExternalVibrationTest.java
@@ -0,0 +1,47 @@
1+/*
2+ * Copyright (C) 2020 The Android Open Source Project
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+package android.os;
18+
19+import static junit.framework.Assert.assertEquals;
20+
21+import static org.mockito.Mockito.mock;
22+
23+import android.media.AudioAttributes;
24+
25+import org.junit.Test;
26+import org.junit.runner.RunWith;
27+import org.mockito.junit.MockitoJUnitRunner;
28+
29+@RunWith(MockitoJUnitRunner.class)
30+public class ExternalVibrationTest {
31+ @Test
32+ public void testSerialization() {
33+ AudioAttributes audio = new AudioAttributes.Builder().build();
34+ IExternalVibrationController controller = mock(IExternalVibrationController.class);
35+ ExternalVibration original = new ExternalVibration(
36+ 123, // uid
37+ "pkg",
38+ audio,
39+ controller);
40+ Parcel p = Parcel.obtain();
41+ original.writeToParcel(p, 0);
42+ p.setDataPosition(0);
43+ ExternalVibration restored = ExternalVibration.CREATOR.createFromParcel(p);
44+ assertEquals(original, restored);
45+ }
46+}
47+
--- a/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/appops/AppOpsControllerImpl.java
@@ -195,20 +195,32 @@ public class AppOpsControllerImpl implements AppOpsController,
195195 mNotedItems.remove(item);
196196 if (DEBUG) Log.w(TAG, "Removed item: " + item.toString());
197197 }
198- notifySuscribers(code, uid, packageName, false);
198+ boolean active;
199+ // Check if the item is also active
200+ synchronized (mActiveItems) {
201+ active = getAppOpItem(mActiveItems, code, uid, packageName) != null;
202+ }
203+ if (!active) {
204+ notifySuscribers(code, uid, packageName, false);
205+ }
199206 }
200207
201- private void addNoted(int code, int uid, String packageName) {
208+ private boolean addNoted(int code, int uid, String packageName) {
202209 AppOpItem item;
210+ boolean createdNew = false;
203211 synchronized (mNotedItems) {
204212 item = getAppOpItem(mNotedItems, code, uid, packageName);
205213 if (item == null) {
206214 item = new AppOpItem(code, uid, packageName, System.currentTimeMillis());
207215 mNotedItems.add(item);
208216 if (DEBUG) Log.w(TAG, "Added item: " + item.toString());
217+ createdNew = true;
209218 }
210219 }
220+ // We should keep this so we make sure it cannot time out.
221+ mBGHandler.removeCallbacksAndMessages(item);
211222 mBGHandler.scheduleRemoval(item, NOTED_OP_TIME_DELAY_MS);
223+ return createdNew;
212224 }
213225
214226 /**
@@ -255,23 +267,46 @@ public class AppOpsControllerImpl implements AppOpsController,
255267
256268 @Override
257269 public void onOpActiveChanged(int code, int uid, String packageName, boolean active) {
258- if (updateActives(code, uid, packageName, active)) {
259- notifySuscribers(code, uid, packageName, active);
270+ if (DEBUG) {
271+ Log.w(TAG, String.format("onActiveChanged(%d,%d,%s,%s", code, uid, packageName,
272+ Boolean.toString(active)));
273+ }
274+ boolean activeChanged = updateActives(code, uid, packageName, active);
275+ if (!activeChanged) return; // early return
276+ // Check if the item is also noted, in that case, there's no update.
277+ boolean alsoNoted;
278+ synchronized (mNotedItems) {
279+ alsoNoted = getAppOpItem(mNotedItems, code, uid, packageName) != null;
280+ }
281+ // If active is true, we only send the update if the op is not actively noted (already true)
282+ // If active is false, we only send the update if the op is not actively noted (prevent
283+ // early removal)
284+ if (!alsoNoted) {
285+ mBGHandler.post(() -> notifySuscribers(code, uid, packageName, active));
260286 }
261287 }
262288
263289 @Override
264290 public void onOpNoted(int code, int uid, String packageName, int result) {
265291 if (DEBUG) {
266- Log.w(TAG, "Op: " + code + " with result " + AppOpsManager.MODE_NAMES[result]);
292+ Log.w(TAG, "Noted op: " + code + " with result "
293+ + AppOpsManager.MODE_NAMES[result] + " for package " + packageName);
267294 }
268295 if (result != AppOpsManager.MODE_ALLOWED) return;
269- addNoted(code, uid, packageName);
270- notifySuscribers(code, uid, packageName, true);
296+ boolean notedAdded = addNoted(code, uid, packageName);
297+ if (!notedAdded) return; // early return
298+ boolean alsoActive;
299+ synchronized (mActiveItems) {
300+ alsoActive = getAppOpItem(mActiveItems, code, uid, packageName) != null;
301+ }
302+ if (!alsoActive) {
303+ mBGHandler.post(() -> notifySuscribers(code, uid, packageName, true));
304+ }
271305 }
272306
273307 private void notifySuscribers(int code, int uid, String packageName, boolean active) {
274308 if (mCallbacksByCode.containsKey(code)) {
309+ if (DEBUG) Log.d(TAG, "Notifying of change in package " + packageName);
275310 for (Callback cb: mCallbacksByCode.get(code)) {
276311 cb.onActiveStateChanged(code, uid, packageName, active);
277312 }
@@ -295,7 +330,7 @@ public class AppOpsControllerImpl implements AppOpsController,
295330
296331 }
297332
298- protected final class H extends Handler {
333+ protected class H extends Handler {
299334 H(Looper looper) {
300335 super(looper);
301336 }
--- a/packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/appops/AppOpsControllerTest.java
@@ -28,6 +28,8 @@ import static org.mockito.Mockito.never;
2828 import static org.mockito.Mockito.times;
2929 import static org.mockito.Mockito.verify;
3030
31+import static java.lang.Thread.sleep;
32+
3133 import android.app.AppOpsManager;
3234 import android.content.pm.PackageManager;
3335 import android.os.UserHandle;
@@ -36,7 +38,6 @@ import android.testing.TestableLooper;
3638
3739 import androidx.test.filters.SmallTest;
3840
39-import com.android.systemui.Dependency;
4041 import com.android.systemui.SysuiTestCase;
4142
4243 import org.junit.Before;
@@ -45,6 +46,8 @@ import org.junit.runner.RunWith;
4546 import org.mockito.Mock;
4647 import org.mockito.MockitoAnnotations;
4748
49+import java.util.List;
50+
4851 @SmallTest
4952 @RunWith(AndroidTestingRunner.class)
5053 @TestableLooper.RunWithLooper
@@ -63,14 +66,16 @@ public class AppOpsControllerTest extends SysuiTestCase {
6366 private AppOpsControllerImpl.H mMockHandler;
6467
6568 private AppOpsControllerImpl mController;
69+ private TestableLooper mTestableLooper;
6670
6771 @Before
6872 public void setUp() {
6973 MockitoAnnotations.initMocks(this);
74+ mTestableLooper = TestableLooper.get(this);
7075
7176 getContext().addMockSystemService(AppOpsManager.class, mAppOpsManager);
7277
73- mController = new AppOpsControllerImpl(mContext, Dependency.get(Dependency.BG_LOOPER));
78+ mController = new AppOpsControllerImpl(mContext, mTestableLooper.getLooper());
7479 }
7580
7681 @Test
@@ -94,6 +99,7 @@ public class AppOpsControllerTest extends SysuiTestCase {
9499 AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
95100 mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
96101 AppOpsManager.MODE_ALLOWED);
102+ mTestableLooper.processAllMessages();
97103 verify(mCallback).onActiveStateChanged(AppOpsManager.OP_RECORD_AUDIO,
98104 TEST_UID, TEST_PACKAGE_NAME, true);
99105 }
@@ -103,6 +109,7 @@ public class AppOpsControllerTest extends SysuiTestCase {
103109 mController.addCallback(new int[]{AppOpsManager.OP_FINE_LOCATION}, mCallback);
104110 mController.onOpActiveChanged(
105111 AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
112+ mTestableLooper.processAllMessages();
106113 verify(mCallback, never()).onActiveStateChanged(
107114 anyInt(), anyInt(), anyString(), anyBoolean());
108115 }
@@ -113,6 +120,7 @@ public class AppOpsControllerTest extends SysuiTestCase {
113120 mController.removeCallback(new int[]{AppOpsManager.OP_RECORD_AUDIO}, mCallback);
114121 mController.onOpActiveChanged(
115122 AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
123+ mTestableLooper.processAllMessages();
116124 verify(mCallback, never()).onActiveStateChanged(
117125 anyInt(), anyInt(), anyString(), anyBoolean());
118126 }
@@ -123,6 +131,7 @@ public class AppOpsControllerTest extends SysuiTestCase {
123131 mController.removeCallback(new int[]{AppOpsManager.OP_CAMERA}, mCallback);
124132 mController.onOpActiveChanged(
125133 AppOpsManager.OP_RECORD_AUDIO, TEST_UID, TEST_PACKAGE_NAME, true);
134+ mTestableLooper.processAllMessages();
126135 verify(mCallback).onActiveStateChanged(AppOpsManager.OP_RECORD_AUDIO,
127136 TEST_UID, TEST_PACKAGE_NAME, true);
128137 }
@@ -185,4 +194,129 @@ public class AppOpsControllerTest extends SysuiTestCase {
185194 verify(mMockHandler).removeCallbacksAndMessages(null);
186195 assertTrue(mController.getActiveAppOps().isEmpty());
187196 }
197+
198+ @Test
199+ public void noDoubleUpdateOnOpNoted() {
200+ mController.setBGHandler(mMockHandler);
201+
202+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
203+ AppOpsManager.MODE_ALLOWED);
204+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
205+ AppOpsManager.MODE_ALLOWED);
206+
207+ // Only one post to notify subscribers
208+ verify(mMockHandler, times(1)).post(any());
209+
210+ List<AppOpItem> list = mController.getActiveAppOps();
211+ assertEquals(1, list.size());
212+ }
213+
214+ @Test
215+ public void onDoubleOPNoted_scheduleTwiceForRemoval() {
216+ mController.setBGHandler(mMockHandler);
217+
218+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
219+ AppOpsManager.MODE_ALLOWED);
220+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
221+ AppOpsManager.MODE_ALLOWED);
222+
223+ // Only one post to notify subscribers
224+ verify(mMockHandler, times(2)).scheduleRemoval(any(), anyLong());
225+ }
226+
227+ @Test
228+ public void testActiveOpNotRemovedAfterNoted() throws InterruptedException {
229+ // Replaces the timeout delay with 5 ms
230+ AppOpsControllerImpl.H testHandler = mController.new H(mTestableLooper.getLooper()) {
231+ @Override
232+ public void scheduleRemoval(AppOpItem item, long timeToRemoval) {
233+ super.scheduleRemoval(item, 5L);
234+ }
235+ };
236+
237+ mController.addCallback(new int[]{AppOpsManager.OP_FINE_LOCATION}, mCallback);
238+ mController.setBGHandler(testHandler);
239+
240+ mController.onOpActiveChanged(
241+ AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, true);
242+
243+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
244+ AppOpsManager.MODE_ALLOWED);
245+
246+ mTestableLooper.processAllMessages();
247+ List<AppOpItem> list = mController.getActiveAppOps();
248+ verify(mCallback).onActiveStateChanged(
249+ AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, true);
250+
251+ // Duplicates are not removed between active and noted
252+ assertEquals(2, list.size());
253+
254+ sleep(10L);
255+
256+ mTestableLooper.processAllMessages();
257+
258+ verify(mCallback, never()).onActiveStateChanged(
259+ AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, false);
260+ list = mController.getActiveAppOps();
261+ assertEquals(1, list.size());
262+ }
263+
264+ @Test
265+ public void testNotedNotRemovedAfterActive() {
266+ mController.addCallback(new int[]{AppOpsManager.OP_FINE_LOCATION}, mCallback);
267+
268+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
269+ AppOpsManager.MODE_ALLOWED);
270+
271+ mController.onOpActiveChanged(
272+ AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, true);
273+
274+ mTestableLooper.processAllMessages();
275+ List<AppOpItem> list = mController.getActiveAppOps();
276+ verify(mCallback).onActiveStateChanged(
277+ AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, true);
278+
279+ // Duplicates are not removed between active and noted
280+ assertEquals(2, list.size());
281+
282+ mController.onOpActiveChanged(
283+ AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, false);
284+
285+ mTestableLooper.processAllMessages();
286+
287+ verify(mCallback, never()).onActiveStateChanged(
288+ AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, false);
289+ list = mController.getActiveAppOps();
290+ assertEquals(1, list.size());
291+ }
292+
293+ @Test
294+ public void testNotedAndActiveOnlyOneCall() {
295+ mController.addCallback(new int[]{AppOpsManager.OP_FINE_LOCATION}, mCallback);
296+
297+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
298+ AppOpsManager.MODE_ALLOWED);
299+
300+ mController.onOpActiveChanged(
301+ AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, true);
302+
303+ mTestableLooper.processAllMessages();
304+ verify(mCallback).onActiveStateChanged(
305+ AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, true);
306+ }
307+
308+ @Test
309+ public void testActiveAndNotedOnlyOneCall() {
310+ mController.addCallback(new int[]{AppOpsManager.OP_FINE_LOCATION}, mCallback);
311+
312+ mController.onOpActiveChanged(
313+ AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, true);
314+
315+ mController.onOpNoted(AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME,
316+ AppOpsManager.MODE_ALLOWED);
317+
318+ mTestableLooper.processAllMessages();
319+ verify(mCallback).onActiveStateChanged(
320+ AppOpsManager.OP_FINE_LOCATION, TEST_UID, TEST_PACKAGE_NAME, true);
321+ }
188322 }
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -18094,36 +18094,48 @@ public class PackageManagerService extends IPackageManager.Stub
1809418094 int count = 0;
1809518095 final String packageName = pkg.packageName;
1809618096
18097+ boolean handlesWebUris = false;
18098+ final boolean alreadyVerified;
1809718099 synchronized (mPackages) {
1809818100 // If this is a new install and we see that we've already run verification for this
1809918101 // package, we have nothing to do: it means the state was restored from backup.
18100- if (!replacing) {
18101- IntentFilterVerificationInfo ivi =
18102- mSettings.getIntentFilterVerificationLPr(packageName);
18103- if (ivi != null) {
18104- if (DEBUG_DOMAIN_VERIFICATION) {
18105- Slog.i(TAG, "Package " + packageName+ " already verified: status="
18106- + ivi.getStatusString());
18107- }
18108- return;
18102+ final IntentFilterVerificationInfo ivi =
18103+ mSettings.getIntentFilterVerificationLPr(packageName);
18104+ alreadyVerified = (ivi != null);
18105+ if (!replacing && alreadyVerified) {
18106+ if (DEBUG_DOMAIN_VERIFICATION) {
18107+ Slog.i(TAG, "Package " + packageName + " already verified: status="
18108+ + ivi.getStatusString());
1810918109 }
18110+ return;
1811018111 }
1811118112
18112- // If any filters need to be verified, then all need to be.
18113+ // If any filters need to be verified, then all need to be. In addition, we need to
18114+ // know whether an updating app has any web navigation intent filters, to re-
18115+ // examine handling policy even if not re-verifying.
1811318116 boolean needToVerify = false;
1811418117 for (PackageParser.Activity a : pkg.activities) {
1811518118 for (ActivityIntentInfo filter : a.intents) {
18119+ if (filter.handlesWebUris(true)) {
18120+ handlesWebUris = true;
18121+ }
1811618122 if (filter.needsVerification() && needsNetworkVerificationLPr(filter)) {
1811718123 if (DEBUG_DOMAIN_VERIFICATION) {
1811818124 Slog.d(TAG,
1811918125 "Intent filter needs verification, so processing all filters");
1812018126 }
1812118127 needToVerify = true;
18128+ // It's safe to break out here because filter.needsVerification()
18129+ // can only be true if filter.handlesWebUris(true) returns true, so
18130+ // we've already noted that.
1812218131 break;
1812318132 }
1812418133 }
1812518134 }
1812618135
18136+ // Note whether this app publishes any web navigation handling support at all,
18137+ // and whether there are any web-nav filters that fit the profile for running
18138+ // a verification pass now.
1812718139 if (needToVerify) {
1812818140 final int verificationId = mIntentFilterVerificationToken++;
1812918141 for (PackageParser.Activity a : pkg.activities) {
@@ -18141,13 +18153,23 @@ public class PackageManagerService extends IPackageManager.Stub
1814118153 }
1814218154
1814318155 if (count > 0) {
18156+ // count > 0 means that we're running a full verification pass
1814418157 if (DEBUG_DOMAIN_VERIFICATION) Slog.d(TAG, "Starting " + count
1814518158 + " IntentFilter verification" + (count > 1 ? "s" : "")
1814618159 + " for userId:" + userId);
1814718160 mIntentFilterVerifier.startVerifications(userId);
18161+ } else if (alreadyVerified && handlesWebUris) {
18162+ // App used autoVerify in the past, no longer does, but still handles web
18163+ // navigation starts.
18164+ if (DEBUG_DOMAIN_VERIFICATION) {
18165+ Slog.d(TAG, "App changed web filters but no longer verifying - resetting policy");
18166+ }
18167+ synchronized (mPackages) {
18168+ clearIntentFilterVerificationsLPw(packageName, userId);
18169+ }
1814818170 } else {
1814918171 if (DEBUG_DOMAIN_VERIFICATION) {
18150- Slog.d(TAG, "No filters or not all autoVerify for " + packageName);
18172+ Slog.d(TAG, "No web filters or no prior verify policy for " + packageName);
1815118173 }
1815218174 }
1815318175 }
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -1252,6 +1252,7 @@ public final class Settings {
12521252 return false;
12531253 }
12541254 ps.clearDomainVerificationStatusForUser(userId);
1255+ ps.setIntentFilterVerificationInfo(null);
12551256 return true;
12561257 }
12571258