2013-06-11 14:45:48 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2013 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 android.app.SearchManager;
|
2014-07-22 13:48:29 -07:00
|
|
|
import android.content.ComponentName;
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.content.Intent;
|
|
|
|
|
import android.content.IntentFilter;
|
2013-06-14 20:17:30 -04:00
|
|
|
import android.util.Log;
|
2015-01-08 16:59:04 -08:00
|
|
|
|
2015-05-19 12:52:12 -07:00
|
|
|
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
|
2014-04-30 03:02:21 +01:00
|
|
|
import com.android.launcher3.compat.LauncherAppsCompat;
|
2014-10-13 11:33:11 -07:00
|
|
|
import com.android.launcher3.compat.PackageInstallerCompat;
|
2015-03-18 14:16:05 -07:00
|
|
|
import com.android.launcher3.util.Thunk;
|
2015-01-08 16:59:04 -08:00
|
|
|
|
2013-06-11 14:45:48 -04:00
|
|
|
import java.lang.ref.WeakReference;
|
|
|
|
|
|
2015-05-21 20:46:33 -07:00
|
|
|
public class LauncherAppState {
|
2014-02-14 16:59:24 -05:00
|
|
|
|
2014-01-09 17:14:01 -08:00
|
|
|
private final AppFilter mAppFilter;
|
|
|
|
|
private final BuildInfo mBuildInfo;
|
2015-03-18 14:16:05 -07:00
|
|
|
@Thunk final LauncherModel mModel;
|
2014-11-10 18:05:31 -08:00
|
|
|
private final IconCache mIconCache;
|
2015-03-19 14:31:19 -07:00
|
|
|
private final WidgetPreviewLoader mWidgetCache;
|
2014-11-10 18:05:31 -08:00
|
|
|
|
2013-11-13 17:59:46 +01:00
|
|
|
private boolean mWallpaperChangedSinceLastCheck;
|
2013-06-11 14:45:48 -04:00
|
|
|
|
2013-06-25 15:13:26 -04:00
|
|
|
private static WeakReference<LauncherProvider> sLauncherProvider;
|
|
|
|
|
private static Context sContext;
|
2013-06-11 14:45:48 -04:00
|
|
|
|
2013-06-25 15:13:26 -04:00
|
|
|
private static LauncherAppState INSTANCE;
|
2013-06-11 14:45:48 -04:00
|
|
|
|
2015-05-06 11:42:25 -07:00
|
|
|
private InvariantDeviceProfile mInvariantDeviceProfile;
|
2015-06-11 16:18:39 -07:00
|
|
|
|
2015-01-23 16:11:55 -08:00
|
|
|
private LauncherAccessibilityDelegate mAccessibilityDelegate;
|
2013-08-12 16:19:28 -07:00
|
|
|
|
2013-06-11 14:45:48 -04:00
|
|
|
public static LauncherAppState getInstance() {
|
2013-06-25 15:13:26 -04:00
|
|
|
if (INSTANCE == null) {
|
|
|
|
|
INSTANCE = new LauncherAppState();
|
|
|
|
|
}
|
2013-06-11 14:45:48 -04:00
|
|
|
return INSTANCE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-04 10:42:14 -04:00
|
|
|
public static LauncherAppState getInstanceNoCreate() {
|
|
|
|
|
return INSTANCE;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-11 14:45:48 -04:00
|
|
|
public Context getContext() {
|
2013-06-25 15:13:26 -04:00
|
|
|
return sContext;
|
2013-06-11 14:45:48 -04:00
|
|
|
}
|
|
|
|
|
|
2013-06-25 15:13:26 -04:00
|
|
|
public static void setApplicationContext(Context context) {
|
|
|
|
|
if (sContext != null) {
|
2013-06-27 21:47:55 -04:00
|
|
|
Log.w(Launcher.TAG, "setApplicationContext called twice! old=" + sContext + " new=" + context);
|
2013-06-25 15:13:26 -04:00
|
|
|
}
|
|
|
|
|
sContext = context.getApplicationContext();
|
|
|
|
|
}
|
2013-06-14 20:17:30 -04:00
|
|
|
|
2013-06-25 15:13:26 -04:00
|
|
|
private LauncherAppState() {
|
|
|
|
|
if (sContext == null) {
|
|
|
|
|
throw new IllegalStateException("LauncherAppState inited before app context set");
|
|
|
|
|
}
|
2013-06-11 14:45:48 -04:00
|
|
|
|
2013-06-25 15:13:26 -04:00
|
|
|
Log.v(Launcher.TAG, "LauncherAppState inited");
|
2013-06-12 00:38:25 -04:00
|
|
|
|
2013-06-25 15:13:26 -04:00
|
|
|
if (sContext.getResources().getBoolean(R.bool.debug_memory_enabled)) {
|
|
|
|
|
MemoryTracker.startTrackingMe(sContext, "L");
|
2013-06-14 20:17:30 -04:00
|
|
|
}
|
|
|
|
|
|
2015-05-06 11:42:25 -07:00
|
|
|
mInvariantDeviceProfile = new InvariantDeviceProfile(sContext);
|
|
|
|
|
mIconCache = new IconCache(sContext, mInvariantDeviceProfile);
|
2015-06-12 21:18:53 -07:00
|
|
|
mWidgetCache = new WidgetPreviewLoader(sContext, mIconCache);
|
2013-10-03 22:31:03 +01:00
|
|
|
|
|
|
|
|
mAppFilter = AppFilter.loadByName(sContext.getString(R.string.app_filter_class));
|
2014-01-09 17:14:01 -08:00
|
|
|
mBuildInfo = BuildInfo.loadByName(sContext.getString(R.string.build_info_class));
|
2013-10-03 22:31:03 +01:00
|
|
|
mModel = new LauncherModel(this, mIconCache, mAppFilter);
|
2015-03-19 13:18:44 -07:00
|
|
|
|
|
|
|
|
LauncherAppsCompat.getInstance(sContext).addOnAppsChangedCallback(mModel);
|
2013-06-11 14:45:48 -04:00
|
|
|
|
|
|
|
|
// Register intent receivers
|
2014-04-30 03:02:21 +01:00
|
|
|
IntentFilter filter = new IntentFilter();
|
2013-06-11 14:45:48 -04:00
|
|
|
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
|
|
|
|
|
filter.addAction(SearchManager.INTENT_GLOBAL_SEARCH_ACTIVITY_CHANGED);
|
|
|
|
|
filter.addAction(SearchManager.INTENT_ACTION_SEARCHABLES_CHANGED);
|
2015-05-01 13:02:20 -07:00
|
|
|
// For handling managed profiles
|
|
|
|
|
filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_ADDED);
|
|
|
|
|
filter.addAction(LauncherAppsCompat.ACTION_MANAGED_PROFILE_REMOVED);
|
|
|
|
|
|
2013-06-25 15:13:26 -04:00
|
|
|
sContext.registerReceiver(mModel, filter);
|
2013-06-11 14:45:48 -04:00
|
|
|
}
|
2014-05-08 18:52:50 +01:00
|
|
|
|
2013-06-11 14:45:48 -04:00
|
|
|
/**
|
|
|
|
|
* Call from Application.onTerminate(), which is not guaranteed to ever be called.
|
|
|
|
|
*/
|
|
|
|
|
public void onTerminate() {
|
2013-06-25 15:13:26 -04:00
|
|
|
sContext.unregisterReceiver(mModel);
|
2014-05-08 18:52:50 +01:00
|
|
|
final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(sContext);
|
2014-06-30 12:30:31 +01:00
|
|
|
launcherApps.removeOnAppsChangedCallback(mModel);
|
2014-10-13 11:33:11 -07:00
|
|
|
PackageInstallerCompat.getInstance(sContext).onStop();
|
2013-06-11 14:45:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-03-30 11:11:46 -07:00
|
|
|
* Reloads the workspace items from the DB and re-binds the workspace. This should generally
|
|
|
|
|
* not be called as DB updates are automatically followed by UI update
|
2013-06-11 14:45:48 -04:00
|
|
|
*/
|
2015-03-30 11:11:46 -07:00
|
|
|
public void reloadWorkspace() {
|
|
|
|
|
mModel.resetLoadedState(false, true);
|
|
|
|
|
mModel.startLoaderFromBackground();
|
|
|
|
|
}
|
2013-06-11 14:45:48 -04:00
|
|
|
|
|
|
|
|
LauncherModel setLauncher(Launcher launcher) {
|
2015-06-12 21:18:53 -07:00
|
|
|
getLauncherProvider().setLauncherProviderChangeListener(launcher);
|
2013-06-11 14:45:48 -04:00
|
|
|
mModel.initialize(launcher);
|
2015-01-08 16:59:04 -08:00
|
|
|
mAccessibilityDelegate = ((launcher != null) && Utilities.isLmpOrAbove()) ?
|
|
|
|
|
new LauncherAccessibilityDelegate(launcher) : null;
|
2013-06-11 14:45:48 -04:00
|
|
|
return mModel;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 19:01:34 -07:00
|
|
|
public LauncherAccessibilityDelegate getAccessibilityDelegate() {
|
2015-01-08 16:59:04 -08:00
|
|
|
return mAccessibilityDelegate;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-29 17:20:55 -07:00
|
|
|
public IconCache getIconCache() {
|
2013-06-11 14:45:48 -04:00
|
|
|
return mIconCache;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-08 18:13:46 -07:00
|
|
|
public LauncherModel getModel() {
|
2013-06-11 14:45:48 -04:00
|
|
|
return mModel;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-25 15:13:26 -04:00
|
|
|
static void setLauncherProvider(LauncherProvider provider) {
|
|
|
|
|
sLauncherProvider = new WeakReference<LauncherProvider>(provider);
|
2013-06-11 14:45:48 -04:00
|
|
|
}
|
|
|
|
|
|
2013-06-25 15:13:26 -04:00
|
|
|
static LauncherProvider getLauncherProvider() {
|
|
|
|
|
return sLauncherProvider.get();
|
2013-06-12 00:38:25 -04:00
|
|
|
}
|
|
|
|
|
|
2013-06-11 14:45:48 -04:00
|
|
|
public static String getSharedPreferencesKey() {
|
2014-10-09 17:04:09 +01:00
|
|
|
return LauncherFiles.SHARED_PREFERENCES_KEY;
|
2013-06-11 14:45:48 -04:00
|
|
|
}
|
|
|
|
|
|
2015-03-19 14:31:19 -07:00
|
|
|
public WidgetPreviewLoader getWidgetCache() {
|
|
|
|
|
return mWidgetCache;
|
|
|
|
|
}
|
2015-06-02 11:24:28 -07:00
|
|
|
|
2013-11-13 17:59:46 +01:00
|
|
|
public void onWallpaperChanged() {
|
|
|
|
|
mWallpaperChangedSinceLastCheck = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasWallpaperChangedSinceLastCheck() {
|
|
|
|
|
boolean result = mWallpaperChangedSinceLastCheck;
|
|
|
|
|
mWallpaperChangedSinceLastCheck = false;
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-06 11:42:25 -07:00
|
|
|
public InvariantDeviceProfile getInvariantDeviceProfile() {
|
|
|
|
|
return mInvariantDeviceProfile;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-13 13:45:07 -08:00
|
|
|
public static boolean isDogfoodBuild() {
|
|
|
|
|
return getInstance().mBuildInfo.isDogfoodBuild();
|
|
|
|
|
}
|
2013-06-11 14:45:48 -04:00
|
|
|
}
|