Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kk4.4 #17

Open
wants to merge 12 commits into
base: kk4.4
Choose a base branch
from
88 changes: 87 additions & 1 deletion core/java/android/app/Activity.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@
import android.text.method.TextKeyListener;
import android.util.AttributeSet;
import android.util.EventLog;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.util.PrintWriterPrinter;
import android.util.Slog;
import android.util.SparseArray;
import android.view.ActionMode;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.ContextThemeWrapper;
import android.view.Display;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
Expand Down Expand Up @@ -1506,6 +1510,9 @@ public void onConfigurationChanged(Configuration newConfig) {
if (mWindow != null) {
// Pass the configuration changed event to the window
mWindow.onConfigurationChanged(newConfig);
if (mWindow.mIsFloatingWindow) {
scaleFloatingWindow(null);
}
}

if (mActionBar != null) {
Expand Down Expand Up @@ -4235,6 +4242,10 @@ public void finish() {
}
}

public void finishFloating() {
mMainThread.performFinishFloating();
}

/**
* Finish this activity as well as all activities immediately below it
* in the current task that have the same affinity. This is typically
Expand Down Expand Up @@ -5197,7 +5208,10 @@ final void attach(Context context, ActivityThread aThread,

mFragments.attachActivity(this, mContainer, null);

mWindow = PolicyManager.makeNewWindow(this);
if (makeNewWindow(context, intent, info)) {
parent = null;
}

mWindow.setCallback(this);
mWindow.getLayoutInflater().setPrivateFactory(this);
if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
Expand Down Expand Up @@ -5232,6 +5246,70 @@ final void attach(Context context, ActivityThread aThread,
mCurrentConfig = config;
}

private boolean makeNewWindow(Context context, Intent intent, ActivityInfo info) {
boolean floating = (intent.getFlags() & Intent.FLAG_FLOATING_WINDOW) == Intent.FLAG_FLOATING_WINDOW;
boolean history = (intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY;
if (intent != null && floating && !history) {

TypedArray styleArray = context.obtainStyledAttributes(info.theme, com.android.internal.R.styleable.Window);
TypedValue backgroundValue = styleArray.peekValue(com.android.internal.R.styleable.Window_windowBackground);

// Apps that have no title don't need no title bar
TypedValue outValue = new TypedValue();
boolean result = styleArray.getValue(com.android.internal.R.styleable.Window_windowNoTitle, outValue);

if (backgroundValue != null && backgroundValue.toString().contains("light")) {
context.getTheme().applyStyle(com.android.internal.R.style.Theme_DeviceDefault_FloatingWindowLight, true);
} else {
context.getTheme().applyStyle(com.android.internal.R.style.Theme_DeviceDefault_FloatingWindow, true);
}

// Create our new window
mWindow = PolicyManager.makeNewWindow(this);
mWindow.mIsFloatingWindow = true;
mWindow.setCloseOnTouchOutsideIfNotSet(true);
mWindow.setGravity(Gravity.CENTER);

if (android.os.Process.myUid() == android.os.Process.SYSTEM_UID) {
mWindow.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
WindowManager.LayoutParams params = mWindow.getAttributes();
params.alpha = 1f;
params.dimAmount = 0.25f;
mWindow.setAttributes((android.view.WindowManager.LayoutParams) params);
}

// Scale it
scaleFloatingWindow(context);

return true;
} else {
mWindow = PolicyManager.makeNewWindow(this);

return false;
}
}

private void scaleFloatingWindow(Context context) {
if (!mWindow.mIsFloatingWindow) {
return;
}
WindowManager wm = null;
if (context != null) {
wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
} else {
wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
}
Display display = wm.getDefaultDisplay();
DisplayMetrics metrics = new DisplayMetrics();
display.getMetrics(metrics);
if (metrics.heightPixels > metrics.widthPixels) {
mWindow.setLayout((int)(metrics.widthPixels * 0.9f), (int)(metrics.heightPixels * 0.7f));
} else {
mWindow.setLayout((int)(metrics.widthPixels * 0.7f), (int)(metrics.heightPixels * 0.8f));
}
}

/** @hide */
public final IBinder getActivityToken() {
return mParent != null ? mParent.getActivityToken() : mToken;
Expand Down Expand Up @@ -5404,6 +5482,14 @@ final void performStop() {
mStopped = true;
}
mResumed = false;

// Floatingwindows activities should be kept volatile to prevent new activities taking
// up front in a minimized space. Every stop call, for instance when pressing home,
// will terminate the activity. If the activity is already finishing we might just
// as well let it go.
if (!mChangingConfigurations && mWindow != null && mWindow.mIsFloatingWindow && !isFinishing()) {
finish();
}
}

final void performDestroy() {
Expand Down
19 changes: 13 additions & 6 deletions core/java/android/app/ActivityThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,18 @@ public final Activity getActivity(IBinder token) {
return mActivities.get(token).activity;
}

protected void performFinishFloating() {
synchronized (mPackages) {
Activity a = null;
for (ActivityClientRecord ar : mActivities.values()) {
a = ar.activity;
if (a != null && !a.mFinished && a.getWindow() != null && a.getWindow().mIsFloatingWindow) {
a.finish();
}
}
}
}

public final void sendActivityResult(
IBinder token, String id, int requestCode,
int resultCode, Intent data) {
Expand Down Expand Up @@ -2787,12 +2799,7 @@ public final ActivityClientRecord performResumeActivity(IBinder token,
r.stopped = false;
r.state = null;
} catch (Exception e) {
if (!mInstrumentation.onException(r.activity, e)) {
throw new RuntimeException(
"Unable to resume activity "
+ r.intent.getComponent().toShortString()
+ ": " + e.toString(), e);
}
// Unable to resume activity
}
}
return r;
Expand Down
13 changes: 12 additions & 1 deletion core/java/android/app/INotificationManager.aidl
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,15 @@ interface INotificationManager
void cancelAllNotificationsFromListener(in INotificationListener token);

StatusBarNotification[] getActiveNotificationsFromListener(in INotificationListener token);
}

// Halo
void setHaloPolicyBlack(boolean state);
void setHaloStatus(String pkg, boolean status);
void setHaloBlacklistStatus(String pkg, boolean status);
void setHaloWhitelistStatus(String pkg, boolean status);
boolean isHaloPolicyBlack();
boolean isPackageAllowedForHalo(String pkg);

StatusBarNotification[] getActiveNotificationsFromSystemListener(in INotificationListener token);
void cancelNotificationFromSystemListener(in INotificationListener token, String pkg, String tag, int id);
}
8 changes: 8 additions & 0 deletions core/java/android/app/Instrumentation.java
Original file line number Diff line number Diff line change
Expand Up @@ -1469,10 +1469,18 @@ public void execStartActivitiesAsUser(Context who, IBinder contextThread,
}
}
try {
// we must resolve if the last intent in the stack is floating to give the flag to the previous
boolean floating = false;
if (intents.length > 0) {
floating = (intents[intents.length - 1].getFlags()&Intent.FLAG_FLOATING_WINDOW) == Intent.FLAG_FLOATING_WINDOW;
}
String[] resolvedTypes = new String[intents.length];
for (int i=0; i<intents.length; i++) {
intents[i].migrateExtraStreamToClipData();
intents[i].prepareToLeaveProcess();
if (floating) {
intents[i].addFlags(Intent.FLAG_FLOATING_WINDOW);
}
resolvedTypes[i] = intents[i].resolveTypeIfNeeded(who.getContentResolver());
}
int result = ActivityManagerNative.getDefault()
Expand Down
18 changes: 15 additions & 3 deletions core/java/android/app/TaskStackBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class TaskStackBuilder {

private final ArrayList<Intent> mIntents = new ArrayList<Intent>();
private final Context mSourceContext;
private boolean mFirstTaskOnHome = true;

private TaskStackBuilder(Context a) {
mSourceContext = a;
Expand All @@ -78,6 +79,10 @@ public static TaskStackBuilder create(Context context) {
return new TaskStackBuilder(context);
}

public void setTaskOnHome(boolean firstTaskOnHome) {
mFirstTaskOnHome = firstTaskOnHome;
}

/**
* Add a new Intent to the task stack. The most recently added Intent will invoke
* the Activity at the top of the final task stack.
Expand Down Expand Up @@ -298,9 +303,16 @@ public Intent[] getIntents() {
Intent[] intents = new Intent[mIntents.size()];
if (intents.length == 0) return intents;

intents[0] = new Intent(mIntents.get(0)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_TASK_ON_HOME);
Intent newIntent = new Intent(mIntents.get(0));
newIntent.addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK |
Intent.FLAG_ACTIVITY_CLEAR_TASK);

if (mFirstTaskOnHome) {
newIntent.addFlags(Intent.FLAG_ACTIVITY_TASK_ON_HOME);
}

intents[0] = newIntent;
for (int i = 1; i < intents.length; i++) {
intents[i] = new Intent(mIntents.get(i));
}
Expand Down
5 changes: 5 additions & 0 deletions core/java/android/content/Intent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3610,6 +3610,11 @@ public static Intent createChooser(Intent target, CharSequence title) {
* saw. This can only be used in conjunction with {@link #FLAG_ACTIVITY_NEW_TASK}.
*/
public static final int FLAG_ACTIVITY_TASK_ON_HOME = 0X00004000;
/**
* If set, this intent will always match start up as a floating window
* in mutil window scenarios.
*/
public static final int FLAG_FLOATING_WINDOW = 0x00002000;
/**
* If set, when sending a broadcast only registered receivers will be
* called -- no BroadcastReceiver components will be launched.
Expand Down
Loading