Files
Flexera-Launcher/src/com/android/launcher3/BaseActivity.java
T
Winson Chung 3483020c9d Merging ub-launcher3-master, build 6003980
Bug:124967099 P2 Support 5 column layout for all apps (independent of what the workspace layout is)
Bug:126596417 P2 [Gesture Nav] Polish quick switch from home screen
Bug:136278866 P2 Temporary workarounds to make tests pass on Cuttlefish
Bug:136282913 P1 Swipe up from Assistant Fulfillment Card Jank
Bug:138473688 P4 Home settings can't be dismissed by swipe up
Bug:138944598 P4 Merge TaskIconCache into IconCache
Bug:139137636 P2 Create memory tests for Launcher
Bug:139661510 P1 Quickswitch over NGA half shelf doesn't work
Bug:139663018 P2 A home screen shortcut to the Files app keeps being added without my ok.
Bug:140242324 P2 Cache shortcutInfo icons in Launcher
Bug:140252765 P2 Audit Gesture Nav tests (including Back and Quick Switch)
Bug:140337263 P2 Empty launcher (DecorView visibility==4)
Bug:141265005 P4 Overview task should not be tiny if prediction list is shown instead of hotseat
Bug:141484300 P4 Re-enable flicker tests
Bug:141556707 P1 Non-badged work profile app shortcuts getting created on the launcher.
Bug:141568904 P1 Launcher: Unable to add Directions widget
Bug:141770616 P2 Flake: Can't find a launcher object; selector: BySelector [RES='\Qcom.google.android.apps.nexuslauncher:id/deep_shortcuts_container\E'] (visible state: AllApps),
Bug:141886704 P2 Use app targets to determine input consumer instead of launcher state
Bug:141899192 P3 [TalkBack] Page number that TalkBack read doesn't match the current screen on recent apps
Bug:142088072 P2 Turning off the display and then back on takes user back to previous app in live tile mode
Bug:142498588 P4 Feature req: Automatic folder names / creation
Bug:142514365 P1 Failing test AddWidgetTest.testDragIcon
Bug:142753423 P4 Prototype predictive hotseat
Bug:142803200 P1 Broken binder tests
Bug:142828227 P2 Temporary tweaks to make Launcher tests pass in Inproc presubmit
Bug:143107728 P4 Crashes on boot, NPE in nexuslauncher
Bug:143153963 P1 Launcher crashing while trying to tap and launch apps from home screen multiple times.
Bug:143155020 P1 [Failing test] MomoryTests.testAppLaunchFromWorkspace*
Bug:143190879 P1 Pop up "Pixel launcher keeps stopping" when both OTA and mainline are updated before restarting device.
Bug:143249037 P1 Swipe up gesture does not work on wembley-eng
Bug:143285809 P1 [Failing test] TaplTestsQuickstep.testQuickSwitchFromApp
Bug:143307786 P1 Fix screenshot not getting cleaned up after recents animation cancelation
Bug:143353100 P2 [RVC] Stuck in "All set!" after cable restore
Bug:143361207 P3 Can't launch shortcut in live tile mode
Bug:143377934 P4 Tapping on QSB leaves user in live tile mode with empty background
Bug:143639898 P4 Notification dot should animate into popup on long press
Bug:143702640 P2 icon badge is hidden when dragging
Bug:143702700 P4 Drag and drop misbehave
Bug:143714109 P2 Flashing when swipe up and right to launch the previous task
Bug:143773683 P2 [Live tile] App open animation gets cancelled because of screenshot cleanup
Bug:143792840 P4 Pixel launcher keeps stopping
Bug:143803446 P2 "Files" app has one more icon appearing per day
Bug:143857157 P3 Live tile does not follow translationX change of RecentsView
Bug:143904998 P2 Launcher crashes when dragging now playing shortcut
Bug:143991628 P2 Launcher3 App - system apps must target API level 29 or higher
Bug:144081762 P2 Security Vulnerability in AOSP and Pixel Launchers
Bug:144180777 P1 Inproc tests in git_master: getting app icon LauncherTestApp on all apps; Unable to scroll to a clickable icon: LauncherTestApp (visible state: AllApps)
Bug:144290150 P2 Notification dot popups show the wrong notifications
Bug:38268585 P2 Lightning bolt icon missing on recents in Vimeo for OC MR1 and Android P

Test: Manual
Change-Id: I0e329eea927c49217c0446a9e62ceaf3cf0099f0
(cherry picked from commit fa4ecb35adfcdcaf928572f5f0c089b42bb12218)
2019-11-15 22:53:38 +00:00

334 lines
12 KiB
Java

/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.launcher3;
import static com.android.launcher3.util.SystemUiController.UI_STATE_OVERVIEW;
import static java.lang.annotation.RetentionPolicy.SOURCE;
import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.res.Configuration;
import android.view.ContextThemeWrapper;
import androidx.annotation.IntDef;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.logging.StatsLogManager;
import com.android.launcher3.logging.StatsLogUtils;
import com.android.launcher3.logging.StatsLogUtils.LogStateProvider;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate;
import com.android.launcher3.uioverrides.ApiWrapper;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.util.SystemUiController;
import com.android.launcher3.util.ViewCache;
import com.android.launcher3.views.ActivityContext;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.util.ArrayList;
public abstract class BaseActivity extends Activity
implements UserEventDelegate, LogStateProvider, ActivityContext {
public static final int INVISIBLE_BY_STATE_HANDLER = 1 << 0;
public static final int INVISIBLE_BY_APP_TRANSITIONS = 1 << 1;
public static final int INVISIBLE_BY_PENDING_FLAGS = 1 << 2;
// This is not treated as invisibility flag, but adds as a hint for an incomplete transition.
// When the wallpaper animation runs, it replaces this flag with a proper invisibility
// flag, INVISIBLE_BY_PENDING_FLAGS only for the duration of that animation.
public static final int PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION = 1 << 3;
private static final int INVISIBLE_FLAGS =
INVISIBLE_BY_STATE_HANDLER | INVISIBLE_BY_APP_TRANSITIONS | INVISIBLE_BY_PENDING_FLAGS;
public static final int STATE_HANDLER_INVISIBILITY_FLAGS =
INVISIBLE_BY_STATE_HANDLER | PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION;
public static final int INVISIBLE_ALL =
INVISIBLE_FLAGS | PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION;
@Retention(SOURCE)
@IntDef(
flag = true,
value = {INVISIBLE_BY_STATE_HANDLER, INVISIBLE_BY_APP_TRANSITIONS,
INVISIBLE_BY_PENDING_FLAGS, PENDING_INVISIBLE_BY_WALLPAPER_ANIMATION})
public @interface InvisibilityFlags{}
private final ArrayList<OnDeviceProfileChangeListener> mDPChangeListeners = new ArrayList<>();
private final ArrayList<MultiWindowModeChangedListener> mMultiWindowModeChangedListeners =
new ArrayList<>();
protected DeviceProfile mDeviceProfile;
protected UserEventDispatcher mUserEventDispatcher;
protected StatsLogManager mStatsLogManager;
protected SystemUiController mSystemUiController;
public static final int ACTIVITY_STATE_STARTED = 1 << 0;
public static final int ACTIVITY_STATE_RESUMED = 1 << 1;
/**
* State flags indicating that the activity has received one frame after resume, and was
* not immediately paused.
*/
public static final int ACTIVITY_STATE_DEFERRED_RESUMED = 1 << 2;
public static final int ACTIVITY_STATE_WINDOW_FOCUSED = 1 << 3;
/**
* State flag indicating if the user is active or the activity when to background as a result
* of user action.
* @see #isUserActive()
*/
public static final int ACTIVITY_STATE_USER_ACTIVE = 1 << 4;
/**
* State flag indicating that a state transition is in progress
*/
public static final int ACTIVITY_STATE_TRANSITION_ACTIVE = 1 << 5;
@Retention(SOURCE)
@IntDef(
flag = true,
value = {ACTIVITY_STATE_STARTED,
ACTIVITY_STATE_RESUMED,
ACTIVITY_STATE_DEFERRED_RESUMED,
ACTIVITY_STATE_WINDOW_FOCUSED,
ACTIVITY_STATE_USER_ACTIVE,
ACTIVITY_STATE_TRANSITION_ACTIVE})
public @interface ActivityFlags{}
@ActivityFlags
private int mActivityFlags;
// When the recents animation is running, the visibility of the Launcher is managed by the
// animation
@InvisibilityFlags private int mForceInvisible;
private final ViewCache mViewCache = new ViewCache();
public ViewCache getViewCache() {
return mViewCache;
}
@Override
public DeviceProfile getDeviceProfile() {
return mDeviceProfile;
}
public int getCurrentState() { return StatsLogUtils.LAUNCHER_STATE_BACKGROUND; }
public void modifyUserEvent(LauncherLogProto.LauncherEvent event) {}
public final StatsLogManager getStatsLogManager() {
if (mStatsLogManager == null) {
mStatsLogManager = StatsLogManager.newInstance(this, this);
}
return mStatsLogManager;
}
public final UserEventDispatcher getUserEventDispatcher() {
if (mUserEventDispatcher == null) {
mUserEventDispatcher = UserEventDispatcher.newInstance(this, this);
}
return mUserEventDispatcher;
}
public SystemUiController getSystemUiController() {
if (mSystemUiController == null) {
mSystemUiController = new SystemUiController(getWindow());
}
return mSystemUiController;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
@Override
protected void onStart() {
addActivityFlags(ACTIVITY_STATE_STARTED);
super.onStart();
}
@Override
protected void onResume() {
addActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_USER_ACTIVE);
super.onResume();
}
@Override
protected void onUserLeaveHint() {
removeActivityFlags(ACTIVITY_STATE_USER_ACTIVE);
super.onUserLeaveHint();
}
@Override
public void onMultiWindowModeChanged(boolean isInMultiWindowMode, Configuration newConfig) {
super.onMultiWindowModeChanged(isInMultiWindowMode, newConfig);
for (int i = mMultiWindowModeChangedListeners.size() - 1; i >= 0; i--) {
mMultiWindowModeChangedListeners.get(i).onMultiWindowModeChanged(isInMultiWindowMode);
}
}
@Override
protected void onStop() {
removeActivityFlags(ACTIVITY_STATE_STARTED | ACTIVITY_STATE_USER_ACTIVE);
mForceInvisible = 0;
super.onStop();
// Reset the overridden sysui flags used for the task-swipe launch animation, this is a
// catch all for if we do not get resumed (and therefore not paused below)
getSystemUiController().updateUiState(UI_STATE_OVERVIEW, 0);
}
@Override
protected void onPause() {
removeActivityFlags(ACTIVITY_STATE_RESUMED | ACTIVITY_STATE_DEFERRED_RESUMED);
super.onPause();
// Reset the overridden sysui flags used for the task-swipe launch animation, we do this
// here instead of at the end of the animation because the start of the new activity does
// not happen immediately, which would cause us to reset to launcher's sysui flags and then
// back to the new app (causing a flash)
getSystemUiController().updateUiState(UI_STATE_OVERVIEW, 0);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
addActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED);
} else {
removeActivityFlags(ACTIVITY_STATE_WINDOW_FOCUSED);
}
}
public boolean isStarted() {
return (mActivityFlags & ACTIVITY_STATE_STARTED) != 0;
}
/**
* isResumed in already defined as a hidden final method in Activity.java
*/
public boolean hasBeenResumed() {
return (mActivityFlags & ACTIVITY_STATE_RESUMED) != 0;
}
public boolean isUserActive() {
return (mActivityFlags & ACTIVITY_STATE_USER_ACTIVE) != 0;
}
public int getActivityFlags() {
return mActivityFlags;
}
protected void addActivityFlags(int flags) {
mActivityFlags |= flags;
onActivityFlagsChanged(flags);
}
protected void removeActivityFlags(int flags) {
mActivityFlags &= ~flags;
onActivityFlagsChanged(flags);
}
protected void onActivityFlagsChanged(int changeBits) { }
public void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
mDPChangeListeners.add(listener);
}
public void removeOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
mDPChangeListeners.remove(listener);
}
protected void dispatchDeviceProfileChanged() {
for (int i = mDPChangeListeners.size() - 1; i >= 0; i--) {
mDPChangeListeners.get(i).onDeviceProfileChanged(mDeviceProfile);
}
}
public void addMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) {
mMultiWindowModeChangedListeners.add(listener);
}
public void removeMultiWindowModeChangedListener(MultiWindowModeChangedListener listener) {
mMultiWindowModeChangedListeners.remove(listener);
}
/**
* Used to set the override visibility state, used only to handle the transition home with the
* recents animation.
* @see QuickstepAppTransitionManagerImpl#getWallpaperOpenRunner
*/
public void addForceInvisibleFlag(@InvisibilityFlags int flag) {
mForceInvisible |= flag;
}
public void clearForceInvisibleFlag(@InvisibilityFlags int flag) {
mForceInvisible &= ~flag;
}
/**
* @return Wether this activity should be considered invisible regardless of actual visibility.
*/
public boolean isForceInvisible() {
return hasSomeInvisibleFlag(INVISIBLE_FLAGS);
}
public boolean hasSomeInvisibleFlag(int mask) {
return (mForceInvisible & mask) != 0;
}
public interface MultiWindowModeChangedListener {
void onMultiWindowModeChanged(boolean isInMultiWindowMode);
}
@Override
public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) {
if (!ApiWrapper.dumpActivity(this, writer)) {
super.dump(prefix, fd, writer, args);
}
}
protected void dumpMisc(String prefix, PrintWriter writer) {
writer.println(prefix + "deviceProfile isTransposed="
+ getDeviceProfile().isVerticalBarLayout());
writer.println(prefix + "orientation=" + getResources().getConfiguration().orientation);
writer.println(prefix + "mSystemUiController: " + mSystemUiController);
writer.println(prefix + "mActivityFlags: " + mActivityFlags);
writer.println(prefix + "mForceInvisible: " + mForceInvisible);
}
public static <T extends BaseActivity> T fromContext(Context context) {
if (context instanceof BaseActivity) {
return (T) context;
} else if (context instanceof ContextThemeWrapper) {
return fromContext(((ContextWrapper) context).getBaseContext());
} else {
throw new IllegalArgumentException("Cannot find BaseActivity in parent tree");
}
}
}