Skip to content

Commit

Permalink
Merge pull request #14 from BayerischeMotorenWerke/11
Browse files Browse the repository at this point in the history
  • Loading branch information
goodmeow authored May 4, 2022
2 parents 124f433 + 53b9ff2 commit ec50260
Show file tree
Hide file tree
Showing 36 changed files with 619 additions and 132 deletions.
7 changes: 7 additions & 0 deletions core/java/android/accounts/Account.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import com.android.internal.annotations.GuardedBy;

import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -85,6 +86,12 @@ public Account(String name, String type, String accessId) {
if (TextUtils.isEmpty(type)) {
throw new IllegalArgumentException("the type must not be empty: " + type);
}
if (name.length() > 200) {
throw new IllegalArgumentException("account name is longer than 200 characters");
}
if (type.length() > 200) {
throw new IllegalArgumentException("account type is longer than 200 characters");
}
this.name = name;
this.type = type;
this.accessId = accessId;
Expand Down
8 changes: 8 additions & 0 deletions core/java/android/app/admin/DevicePolicyManagerInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package android.app.admin;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.ComponentName;
Expand Down Expand Up @@ -76,6 +77,13 @@ public interface OnCrossProfileWidgetProvidersChangeListener {
public abstract void addOnCrossProfileWidgetProvidersChangeListener(
OnCrossProfileWidgetProvidersChangeListener listener);

/**
* @param userHandle the handle of the user whose profile owner is being fetched.
* @return the configured supervision app if it exists and is the device owner or policy owner.
*/
public abstract @Nullable ComponentName getProfileOwnerOrDeviceOwnerSupervisionComponent(
@NonNull UserHandle userHandle);

/**
* Checks if an app with given uid is an active device admin of its user and has the policy
* specified.
Expand Down
3 changes: 3 additions & 0 deletions core/java/android/debug/AdbManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class AdbManager {
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.MANAGE_DEBUGGING)
public static final String WIRELESS_DEBUG_STATE_CHANGED_ACTION =
"com.android.server.adb.WIRELESS_DEBUG_STATUS";

Expand All @@ -46,6 +47,7 @@ public class AdbManager {
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.MANAGE_DEBUGGING)
public static final String WIRELESS_DEBUG_PAIRED_DEVICES_ACTION =
"com.android.server.adb.WIRELESS_DEBUG_PAIRED_DEVICES";

Expand All @@ -59,6 +61,7 @@ public class AdbManager {
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.MANAGE_DEBUGGING)
public static final String WIRELESS_DEBUG_PAIRING_RESULT_ACTION =
"com.android.server.adb.WIRELESS_DEBUG_PAIRING_RESULT";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.android.internal.app;

import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
Expand All @@ -27,6 +29,7 @@
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.android.internal.R;

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

getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
final Intent intent = getIntent();
mPackageName = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME);
mTarget = intent.getParcelableExtra(Intent.EXTRA_INTENT);
Expand Down
116 changes: 76 additions & 40 deletions core/java/com/android/internal/infra/AndroidFuture.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,21 @@

package com.android.internal.infra;

import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR;

import android.annotation.CallSuper;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Handler;
import android.os.Message;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.util.ExceptionUtils;
import android.util.EventLog;
import android.util.Log;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.Preconditions;
import com.android.internal.util.function.pooled.PooledLambda;

import java.lang.reflect.Constructor;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
Expand Down Expand Up @@ -75,14 +73,16 @@ public class AndroidFuture<T> extends CompletableFuture<T> implements Parcelable

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

private final @NonNull Object mLock = new Object();
@GuardedBy("mLock")
private @Nullable BiConsumer<? super T, ? super Throwable> mListener;
@GuardedBy("mLock")
private @Nullable Executor mListenerExecutor = DIRECT_EXECUTOR;
private @NonNull Handler mTimeoutHandler = Handler.getMain();
private @NonNull Handler mTimeoutHandler = getMainHandler();
private final @Nullable IAndroidFuture mRemoteOrigin;

public AndroidFuture() {
Expand All @@ -96,7 +96,7 @@ public AndroidFuture() {
// Done
if (in.readBoolean()) {
// Failed
completeExceptionally(unparcelException(in));
completeExceptionally(readThrowable(in));
} else {
// Success
complete((T) in.readValue(null));
Expand All @@ -108,6 +108,15 @@ public AndroidFuture() {
}
}

@NonNull
private static Handler getMainHandler() {
// This isn't thread-safe but we are okay with it.
if (sMainHandler == null) {
sMainHandler = new Handler(Looper.getMainLooper());
}
return sMainHandler;
}

/**
* Create a completed future with the given value.
*
Expand Down Expand Up @@ -236,9 +245,7 @@ private void callListenerAsync(BiConsumer<? super T, ? super Throwable> listener
if (mListenerExecutor == DIRECT_EXECUTOR) {
callListener(listener, res, err);
} else {
mListenerExecutor.execute(PooledLambda
.obtainRunnable(AndroidFuture::callListener, listener, res, err)
.recycleOnUse());
mListenerExecutor.execute(() -> callListener(listener, res, err));
}
}

Expand All @@ -260,7 +267,8 @@ static <TT> void callListener(
} else {
// listener exception-case threw
// give up on listener but preserve the original exception when throwing up
throw ExceptionUtils.appendCause(t, err);
t.addSuppressed(err);
throw t;
}
}
} catch (Throwable t2) {
Expand All @@ -272,9 +280,7 @@ static <TT> void callListener(
/** @inheritDoc */
//@Override //TODO uncomment once java 9 APIs are exposed to frameworks
public AndroidFuture<T> orTimeout(long timeout, @NonNull TimeUnit unit) {
Message msg = PooledLambda.obtainMessage(AndroidFuture::triggerTimeout, this);
msg.obj = this;
mTimeoutHandler.sendMessageDelayed(msg, unit.toMillis(timeout));
mTimeoutHandler.postDelayed(this::triggerTimeout, this, unit.toMillis(timeout));
return this;
}

Expand Down Expand Up @@ -507,7 +513,7 @@ public void writeToParcel(Parcel dest, int flags) {
result = get();
} catch (Throwable t) {
dest.writeBoolean(true);
parcelException(dest, unwrapExecutionException(t));
writeThrowable(dest, unwrapExecutionException(t));
return;
}
dest.writeBoolean(false);
Expand Down Expand Up @@ -545,45 +551,75 @@ Throwable unwrapExecutionException(Throwable t) {
* Alternative to {@link Parcel#writeException} that stores the stack trace, in a
* way consistent with the binder IPC exception propagation behavior.
*/
private static void parcelException(Parcel p, @Nullable Throwable t) {
p.writeBoolean(t == null);
if (t == null) {
private static void writeThrowable(@NonNull Parcel parcel, @Nullable Throwable throwable) {
boolean hasThrowable = throwable != null;
parcel.writeBoolean(hasThrowable);
if (!hasThrowable) {
return;
}

boolean isFrameworkParcelable = throwable instanceof Parcelable
&& throwable.getClass().getClassLoader() == Parcelable.class.getClassLoader();
parcel.writeBoolean(isFrameworkParcelable);
if (isFrameworkParcelable) {
parcel.writeParcelable((Parcelable) throwable,
Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
return;
}

p.writeInt(Parcel.getExceptionCode(t));
p.writeString(t.getClass().getName());
p.writeString(t.getMessage());
p.writeStackTrace(t);
parcelException(p, t.getCause());
parcel.writeString(throwable.getClass().getName());
parcel.writeString(throwable.getMessage());
StackTraceElement[] stackTrace = throwable.getStackTrace();
StringBuilder stackTraceBuilder = new StringBuilder();
int truncatedStackTraceLength = Math.min(stackTrace != null ? stackTrace.length : 0, 5);
for (int i = 0; i < truncatedStackTraceLength; i++) {
if (i > 0) {
stackTraceBuilder.append('\n');
}
stackTraceBuilder.append("\tat ").append(stackTrace[i]);
}
parcel.writeString(stackTraceBuilder.toString());
writeThrowable(parcel, throwable.getCause());
}

/**
* @see #parcelException
* @see #writeThrowable
*/
private static @Nullable Throwable unparcelException(Parcel p) {
if (p.readBoolean()) {
private static @Nullable Throwable readThrowable(@NonNull Parcel parcel) {
final boolean hasThrowable = parcel.readBoolean();
if (!hasThrowable) {
return null;
}

int exCode = p.readInt();
String cls = p.readString();
String msg = p.readString();
String stackTrace = p.readInt() > 0 ? p.readString() : "\t<stack trace unavailable>";
msg += "\n" + stackTrace;

Exception ex = p.createExceptionOrNull(exCode, msg);
if (ex == null) {
ex = new RuntimeException(cls + ": " + msg);
boolean isFrameworkParcelable = parcel.readBoolean();
if (isFrameworkParcelable) {
return parcel.readParcelable(Parcelable.class.getClassLoader());
}
ex.setStackTrace(EMPTY_STACK_TRACE);

Throwable cause = unparcelException(p);
String className = parcel.readString();
String message = parcel.readString();
String stackTrace = parcel.readString();
String messageWithStackTrace = message + '\n' + stackTrace;
Throwable throwable;
try {
Class<?> clazz = Class.forName(className, true, Parcelable.class.getClassLoader());
if (Throwable.class.isAssignableFrom(clazz)) {
Constructor<?> constructor = clazz.getConstructor(String.class);
throwable = (Throwable) constructor.newInstance(messageWithStackTrace);
} else {
android.util.EventLog.writeEvent(0x534e4554, "186530450", -1, "");
throwable = new RuntimeException(className + ": " + messageWithStackTrace);
}
} catch (Throwable t) {
throwable = new RuntimeException(className + ": " + messageWithStackTrace);
throwable.addSuppressed(t);
}
throwable.setStackTrace(EMPTY_STACK_TRACE);
Throwable cause = readThrowable(parcel);
if (cause != null) {
ex.initCause(ex);
throwable.initCause(cause);
}

return ex;
return throwable;
}

@Override
Expand Down
Loading

0 comments on commit ec50260

Please sign in to comment.