Skip to content

Commit ec50260

Browse files
authored
Merge pull request #14 from BayerischeMotorenWerke/11
2 parents 124f433 + 53b9ff2 commit ec50260

File tree

36 files changed

+619
-132
lines changed

36 files changed

+619
-132
lines changed

core/java/android/accounts/Account.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import com.android.internal.annotations.GuardedBy;
3232

33+
import java.util.Objects;
3334
import java.util.Set;
3435

3536
/**
@@ -85,6 +86,12 @@ public Account(String name, String type, String accessId) {
8586
if (TextUtils.isEmpty(type)) {
8687
throw new IllegalArgumentException("the type must not be empty: " + type);
8788
}
89+
if (name.length() > 200) {
90+
throw new IllegalArgumentException("account name is longer than 200 characters");
91+
}
92+
if (type.length() > 200) {
93+
throw new IllegalArgumentException("account type is longer than 200 characters");
94+
}
8895
this.name = name;
8996
this.type = type;
9097
this.accessId = accessId;

core/java/android/app/admin/DevicePolicyManagerInternal.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package android.app.admin;
1818

19+
import android.annotation.NonNull;
1920
import android.annotation.Nullable;
2021
import android.annotation.UserIdInt;
2122
import android.content.ComponentName;
@@ -76,6 +77,13 @@ public interface OnCrossProfileWidgetProvidersChangeListener {
7677
public abstract void addOnCrossProfileWidgetProvidersChangeListener(
7778
OnCrossProfileWidgetProvidersChangeListener listener);
7879

80+
/**
81+
* @param userHandle the handle of the user whose profile owner is being fetched.
82+
* @return the configured supervision app if it exists and is the device owner or policy owner.
83+
*/
84+
public abstract @Nullable ComponentName getProfileOwnerOrDeviceOwnerSupervisionComponent(
85+
@NonNull UserHandle userHandle);
86+
7987
/**
8088
* Checks if an app with given uid is an active device admin of its user and has the policy
8189
* specified.

core/java/android/debug/AdbManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class AdbManager {
3838
*
3939
* @hide
4040
*/
41+
@RequiresPermission(android.Manifest.permission.MANAGE_DEBUGGING)
4142
public static final String WIRELESS_DEBUG_STATE_CHANGED_ACTION =
4243
"com.android.server.adb.WIRELESS_DEBUG_STATUS";
4344

@@ -46,6 +47,7 @@ public class AdbManager {
4647
*
4748
* @hide
4849
*/
50+
@RequiresPermission(android.Manifest.permission.MANAGE_DEBUGGING)
4951
public static final String WIRELESS_DEBUG_PAIRED_DEVICES_ACTION =
5052
"com.android.server.adb.WIRELESS_DEBUG_PAIRED_DEVICES";
5153

@@ -59,6 +61,7 @@ public class AdbManager {
5961
*
6062
* @hide
6163
*/
64+
@RequiresPermission(android.Manifest.permission.MANAGE_DEBUGGING)
6265
public static final String WIRELESS_DEBUG_PAIRING_RESULT_ACTION =
6366
"com.android.server.adb.WIRELESS_DEBUG_PAIRING_RESULT";
6467

core/java/com/android/internal/app/HarmfulAppWarningActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.android.internal.app;
1818

19+
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
20+
1921
import android.content.Context;
2022
import android.content.DialogInterface;
2123
import android.content.Intent;
@@ -27,6 +29,7 @@
2729
import android.util.Log;
2830
import android.view.View;
2931
import android.widget.TextView;
32+
3033
import com.android.internal.R;
3134

3235
/**
@@ -48,6 +51,7 @@ public class HarmfulAppWarningActivity extends AlertActivity implements
4851
protected void onCreate(Bundle savedInstanceState) {
4952
super.onCreate(savedInstanceState);
5053

54+
getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
5155
final Intent intent = getIntent();
5256
mPackageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME);
5357
mTarget = intent.getParcelableExtra(Intent.EXTRA_INTENT);

core/java/com/android/internal/infra/AndroidFuture.java

Lines changed: 76 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,21 @@
1616

1717
package com.android.internal.infra;
1818

19-
import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR;
20-
2119
import android.annotation.CallSuper;
2220
import android.annotation.NonNull;
2321
import android.annotation.Nullable;
2422
import android.os.Handler;
25-
import android.os.Message;
23+
import android.os.Looper;
2624
import android.os.Parcel;
2725
import android.os.Parcelable;
2826
import android.os.RemoteException;
29-
import android.util.ExceptionUtils;
27+
import android.util.EventLog;
3028
import android.util.Log;
3129

3230
import com.android.internal.annotations.GuardedBy;
3331
import com.android.internal.util.Preconditions;
34-
import com.android.internal.util.function.pooled.PooledLambda;
3532

33+
import java.lang.reflect.Constructor;
3634
import java.util.concurrent.CancellationException;
3735
import java.util.concurrent.CompletableFuture;
3836
import java.util.concurrent.CompletionStage;
@@ -75,14 +73,16 @@ public class AndroidFuture<T> extends CompletableFuture<T> implements Parcelable
7573

7674
private static final boolean DEBUG = false;
7775
private static final String LOG_TAG = AndroidFuture.class.getSimpleName();
76+
private static final Executor DIRECT_EXECUTOR = Runnable::run;
7877
private static final StackTraceElement[] EMPTY_STACK_TRACE = new StackTraceElement[0];
78+
private static @Nullable Handler sMainHandler;
7979

8080
private final @NonNull Object mLock = new Object();
8181
@GuardedBy("mLock")
8282
private @Nullable BiConsumer<? super T, ? super Throwable> mListener;
8383
@GuardedBy("mLock")
8484
private @Nullable Executor mListenerExecutor = DIRECT_EXECUTOR;
85-
private @NonNull Handler mTimeoutHandler = Handler.getMain();
85+
private @NonNull Handler mTimeoutHandler = getMainHandler();
8686
private final @Nullable IAndroidFuture mRemoteOrigin;
8787

8888
public AndroidFuture() {
@@ -96,7 +96,7 @@ public AndroidFuture() {
9696
// Done
9797
if (in.readBoolean()) {
9898
// Failed
99-
completeExceptionally(unparcelException(in));
99+
completeExceptionally(readThrowable(in));
100100
} else {
101101
// Success
102102
complete((T) in.readValue(null));
@@ -108,6 +108,15 @@ public AndroidFuture() {
108108
}
109109
}
110110

111+
@NonNull
112+
private static Handler getMainHandler() {
113+
// This isn't thread-safe but we are okay with it.
114+
if (sMainHandler == null) {
115+
sMainHandler = new Handler(Looper.getMainLooper());
116+
}
117+
return sMainHandler;
118+
}
119+
111120
/**
112121
* Create a completed future with the given value.
113122
*
@@ -236,9 +245,7 @@ private void callListenerAsync(BiConsumer<? super T, ? super Throwable> listener
236245
if (mListenerExecutor == DIRECT_EXECUTOR) {
237246
callListener(listener, res, err);
238247
} else {
239-
mListenerExecutor.execute(PooledLambda
240-
.obtainRunnable(AndroidFuture::callListener, listener, res, err)
241-
.recycleOnUse());
248+
mListenerExecutor.execute(() -> callListener(listener, res, err));
242249
}
243250
}
244251

@@ -260,7 +267,8 @@ static <TT> void callListener(
260267
} else {
261268
// listener exception-case threw
262269
// give up on listener but preserve the original exception when throwing up
263-
throw ExceptionUtils.appendCause(t, err);
270+
t.addSuppressed(err);
271+
throw t;
264272
}
265273
}
266274
} catch (Throwable t2) {
@@ -272,9 +280,7 @@ static <TT> void callListener(
272280
/** @inheritDoc */
273281
//@Override //TODO uncomment once java 9 APIs are exposed to frameworks
274282
public AndroidFuture<T> orTimeout(long timeout, @NonNull TimeUnit unit) {
275-
Message msg = PooledLambda.obtainMessage(AndroidFuture::triggerTimeout, this);
276-
msg.obj = this;
277-
mTimeoutHandler.sendMessageDelayed(msg, unit.toMillis(timeout));
283+
mTimeoutHandler.postDelayed(this::triggerTimeout, this, unit.toMillis(timeout));
278284
return this;
279285
}
280286

@@ -507,7 +513,7 @@ public void writeToParcel(Parcel dest, int flags) {
507513
result = get();
508514
} catch (Throwable t) {
509515
dest.writeBoolean(true);
510-
parcelException(dest, unwrapExecutionException(t));
516+
writeThrowable(dest, unwrapExecutionException(t));
511517
return;
512518
}
513519
dest.writeBoolean(false);
@@ -545,45 +551,75 @@ Throwable unwrapExecutionException(Throwable t) {
545551
* Alternative to {@link Parcel#writeException} that stores the stack trace, in a
546552
* way consistent with the binder IPC exception propagation behavior.
547553
*/
548-
private static void parcelException(Parcel p, @Nullable Throwable t) {
549-
p.writeBoolean(t == null);
550-
if (t == null) {
554+
private static void writeThrowable(@NonNull Parcel parcel, @Nullable Throwable throwable) {
555+
boolean hasThrowable = throwable != null;
556+
parcel.writeBoolean(hasThrowable);
557+
if (!hasThrowable) {
558+
return;
559+
}
560+
561+
boolean isFrameworkParcelable = throwable instanceof Parcelable
562+
&& throwable.getClass().getClassLoader() == Parcelable.class.getClassLoader();
563+
parcel.writeBoolean(isFrameworkParcelable);
564+
if (isFrameworkParcelable) {
565+
parcel.writeParcelable((Parcelable) throwable,
566+
Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
551567
return;
552568
}
553569

554-
p.writeInt(Parcel.getExceptionCode(t));
555-
p.writeString(t.getClass().getName());
556-
p.writeString(t.getMessage());
557-
p.writeStackTrace(t);
558-
parcelException(p, t.getCause());
570+
parcel.writeString(throwable.getClass().getName());
571+
parcel.writeString(throwable.getMessage());
572+
StackTraceElement[] stackTrace = throwable.getStackTrace();
573+
StringBuilder stackTraceBuilder = new StringBuilder();
574+
int truncatedStackTraceLength = Math.min(stackTrace != null ? stackTrace.length : 0, 5);
575+
for (int i = 0; i < truncatedStackTraceLength; i++) {
576+
if (i > 0) {
577+
stackTraceBuilder.append('\n');
578+
}
579+
stackTraceBuilder.append("\tat ").append(stackTrace[i]);
580+
}
581+
parcel.writeString(stackTraceBuilder.toString());
582+
writeThrowable(parcel, throwable.getCause());
559583
}
560584

561585
/**
562-
* @see #parcelException
586+
* @see #writeThrowable
563587
*/
564-
private static @Nullable Throwable unparcelException(Parcel p) {
565-
if (p.readBoolean()) {
588+
private static @Nullable Throwable readThrowable(@NonNull Parcel parcel) {
589+
final boolean hasThrowable = parcel.readBoolean();
590+
if (!hasThrowable) {
566591
return null;
567592
}
568593

569-
int exCode = p.readInt();
570-
String cls = p.readString();
571-
String msg = p.readString();
572-
String stackTrace = p.readInt() > 0 ? p.readString() : "\t<stack trace unavailable>";
573-
msg += "\n" + stackTrace;
574-
575-
Exception ex = p.createExceptionOrNull(exCode, msg);
576-
if (ex == null) {
577-
ex = new RuntimeException(cls + ": " + msg);
594+
boolean isFrameworkParcelable = parcel.readBoolean();
595+
if (isFrameworkParcelable) {
596+
return parcel.readParcelable(Parcelable.class.getClassLoader());
578597
}
579-
ex.setStackTrace(EMPTY_STACK_TRACE);
580598

581-
Throwable cause = unparcelException(p);
599+
String className = parcel.readString();
600+
String message = parcel.readString();
601+
String stackTrace = parcel.readString();
602+
String messageWithStackTrace = message + '\n' + stackTrace;
603+
Throwable throwable;
604+
try {
605+
Class<?> clazz = Class.forName(className, true, Parcelable.class.getClassLoader());
606+
if (Throwable.class.isAssignableFrom(clazz)) {
607+
Constructor<?> constructor = clazz.getConstructor(String.class);
608+
throwable = (Throwable) constructor.newInstance(messageWithStackTrace);
609+
} else {
610+
android.util.EventLog.writeEvent(0x534e4554, "186530450", -1, "");
611+
throwable = new RuntimeException(className + ": " + messageWithStackTrace);
612+
}
613+
} catch (Throwable t) {
614+
throwable = new RuntimeException(className + ": " + messageWithStackTrace);
615+
throwable.addSuppressed(t);
616+
}
617+
throwable.setStackTrace(EMPTY_STACK_TRACE);
618+
Throwable cause = readThrowable(parcel);
582619
if (cause != null) {
583-
ex.initCause(ex);
620+
throwable.initCause(cause);
584621
}
585-
586-
return ex;
622+
return throwable;
587623
}
588624

589625
@Override

0 commit comments

Comments
 (0)