[Panlingual] Adds a filter of application for per apps locale change.

- Settings -> System -> app language -> app languages
   Use this filter to only show apps allowed to change the locale.
 - Settings -> Apps -> all apps -> any one of app -> language
   Use this filter to only show the language preference of app allowed to change the locale.
Bug: 210935436
Test: atest pass.
Test: local test.
Change-Id: I2f8a0815dae68392e11882ad9e1e4945492efdba
This commit is contained in:
tom hsu
2022-01-04 18:08:28 +08:00
committed by Tom Hsu
parent 0bcd9d1b20
commit 33f2096fea
8 changed files with 356 additions and 18 deletions

View File

@@ -0,0 +1,77 @@
/*
* Copyright (C) 2022 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.settings.applications;
import android.content.Context;
import android.util.Log;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
import com.android.settingslib.applications.ApplicationsState.AppFilter;
import java.util.List;
/**
* Creates a application filter to restrict UI display of applications.
* This is to avoid users from changing the per apps locale
* Also provides app filters that can use the info.
*/
public class AppStateLocaleBridge extends AppStateBaseBridge {
private static final String TAG = AppStateLocaleBridge.class.getSimpleName();
private final Context mContext;
public AppStateLocaleBridge(Context context, ApplicationsState appState,
Callback callback) {
super(appState, callback);
mContext = context;
}
@Override
protected void updateExtraInfo(AppEntry app, String packageName, int uid) {
app.extraInfo = AppLocaleUtil.canDisplayLocaleUi(mContext, app)
? Boolean.TRUE : Boolean.FALSE;
}
@Override
protected void loadAllExtraInfo() {
final List<AppEntry> allApps = mAppSession.getAllApps();
for (int i = 0; i < allApps.size(); i++) {
AppEntry app = allApps.get(i);
app.extraInfo = AppLocaleUtil.canDisplayLocaleUi(mContext, app)
? Boolean.TRUE : Boolean.FALSE;
}
}
/** For the Settings which shows category of per app's locale. */
public static final AppFilter FILTER_APPS_LOCALE =
new AppFilter() {
@Override
public void init() {
}
@Override
public boolean filterApp(AppEntry entry) {
if (entry.extraInfo == null) {
Log.d(TAG, "No extra info.");
return false;
}
return (Boolean) entry.extraInfo;
}
};
}