Launcher應用在CTS測試中出現的幾個問題總結
--- By Wampee.Lan
問題1、CTS Failed:release的apk版本為測試版本,非正式版本
Launcher通過eclipse編譯Run As——AndroidApplication後,在專案bin目錄生成的apk為測試版,可以通過以下程式碼測試當前包名apk是否為測試版:
private boolean isApkDebugable(Contextcontext, String packageName) {
try{
PackageInfopkginfo = context.getPackageManager().getPackageInfo(packageName, 1);
if(pkginfo != null) {
ApplicationInfoinfo = pkginfo.applicationInfo;
return(info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
}
}catch (Exception e) {
}
returnfalse;
}
因此eclipse正確的release方式為,eclipse——Android Tools——Export SignedApplication Package…或者Export UnSignedApplication Package…
問題2、CTS Failed:Launcher CTS測試項BYODManaged Provisionging——Badged work apps visible in Launcher生成的work資料夾圖示沒有置灰
Work資料夾中圖示置灰功能,在Android7.0Launcher CTS上才增加的一個測試項,Android6.0版本的Launcher程式碼沒有關於該屬性的配置。所以將Android7.0 Launcher相關程式碼匯入即可,涉及到主要Java類如下:
com.android.laucnher3.compat.LauncherAppsCompat.java
com.android.laucnher3.compat.UserHandleCompat.java
com.android.laucnher3.compat.UserManagerCompat.java
com.android.laucnher3.compat.UserManagerCompatV16.java
com.android.laucnher3.compat.UserManagerCompatVN.java
問題3、CTS Failed:Launcher CTS測試項BYODManaged Provisionging——Badged work apps visible in Launcher生成的work資料夾裡面圖示沒有顯示公文包圖示,或者有些顯示有些未顯示
分析:CTS——BYOD Managed Provisioning——Badged work apps visible in Launcher測試項,是在當前系統中新增不同使用者work型別的APPS,在設定-系統應用列表中可看到(例如會生成兩個Contacts應用,一個帶公文包圖示,另一個沒有),然後生成一個Work的資料夾,並把相關work資訊的APPS放到work資料夾裡。生成資料夾的操作在Launcher程式碼中執行,具體流程如下:——LauncherModel.loadAllApps(監聽是否有生成work資料夾操作)
finalManagedProfileHeuristic heuristic = ManagedProfileHeuristic.get(mContext,user);
if (heuristic != null) {
final Runnable r = newRunnable() {
@Override
public void run() {
heuristic.processUserApps(apps);
}
};
runOnMainThread(new Runnable() {
@Override
public void run() {
// CheckisLoadingWorkspace on the UI thread, as it is updated on
// the UI thread.
if(mIsLoadingAndBindingWorkspace) {
synchronized(mBindCompleteRunnables) {
mBindCompleteRunnables.add(r);
}
} else {
runOnWorkerThread(r);
}
}
});
}
——ManagedProfileHeuristic. processUserApps(判斷work資料夾是否已建立)
public voidprocessUserApps(List<LauncherActivityInfoCompat> apps) {
initVars();
HashSet<String> packageSet = newHashSet<>();
final boolean userAppsExisted =getUserApps(packageSet);
boolean newPackageAdded = false;
for (LauncherActivityInfoCompat info :apps) {
String packageName =info.getComponentName().getPackageName();
if(!packageSet.contains(packageName)) {
packageSet.add(packageName);
newPackageAdded = true;
markForAddition(info, info.getFirstInstallTime());
}
}
if (newPackageAdded) {
mPrefs.edit().putStringSet(mPackageSetKey, packageSet).apply();
// Do not add shortcuts on thehomescreen for the first time. This prevents the launcher
// getting filled with the manageduser apps, when it start with a fresh DB (or after
// a very long time).
finalizeAdditions(userAppsExisted);
}
}
——ManagedProfileHeuristic.finalizeWorkFolder(建立work資料夾)
private void finalizeWorkFolder() {
if (mWorkFolderApps.isEmpty()) {
return;
}
sortList(mWorkFolderApps);
// Try to get a work folder.
String folderIdKey = USER_FOLDER_ID_PREFIX+ mUserSerial;
if (mPrefs.contains(folderIdKey)) {
long folderId =mPrefs.getLong(folderIdKey, 0);
final FolderInfo workFolder =mModel.findFolderById(folderId);
if (workFolder == null || !workFolder.hasOption(FolderInfo.FLAG_WORK_FOLDER)){
// Could not get a work folder.Add all the icons to homescreen.
mHomescreenApps.addAll(mWorkFolderApps);
return;
}
saveWorkFolderShortcuts(folderId,workFolder.contents.size());
final ArrayList<ShortcutInfo>shortcuts = mWorkFolderApps;
// FolderInfo could already bebound. We need to add shortcuts on the UI thread.
new MainThreadExecutor().execute(newRunnable() {
@Override
public void run() {
for (ShortcutInfo info :shortcuts) {
workFolder.add(info);
}
}
});
} else {
// Create a new folder.
final FolderInfo workFolder = newFolderInfo();
workFolder.title =mContext.getText(R.string.work_folder_name);
workFolder.setOption(FolderInfo.FLAG_WORK_FOLDER, true, null);
// Add all shortcuts before adding it tothe UI, as an empty folder might get deleted.
for (ShortcutInfo info :mWorkFolderApps) {
workFolder.add(info);
}
// Add the item to home screen andDB. This also generates an item id synchronously.
ArrayList<ItemInfo> itemList= new ArrayList<ItemInfo>(1);
itemList.add(workFolder);
mModel.addAndBindAddedWorkspaceItems(mContext, itemList);
mPrefs.edit().putLong(USER_FOLDER_ID_PREFIX+ mUserSerial, workFolder.id).apply();
saveWorkFolderShortcuts(workFolder.id, 0);
}
}
在Work資料夾中的Apps沒有生成公文包圖示是因為Launcher將原生的All Apps放到桌面上,然後新增去重複APP操作LauncherModel.verifyApplications。去重複APP操作,只是將當前重複陣列遇到的第一位去除,導致過濾陣列將帶公文包APP排在首位,過濾掉了帶公文包圖示的APP。而且由於Launcher在後臺是多個執行緒去操作,執行緒執行的先後順序不同,造成新增的過濾陣列排序不一樣,導致在桌面上Apps有時帶公文包有時不帶公文包。
修改方案是優化去重複APP條件,考慮多使用者條件,使其符合CTS規範要求。
以上是近期Launcher在CTS測試中遇到的幾個Failed的問題,供遇到同樣情況的開發者參考。