Merge "Include XmlDom.h for xml::XmlResource" into main
diff --git a/AconfigFlags.bp b/AconfigFlags.bp
index 34a6215..3fea8fc 100644
--- a/AconfigFlags.bp
+++ b/AconfigFlags.bp
@@ -18,10 +18,14 @@
// Add java_aconfig_libraries to here to add them to the core framework
srcs: [
+ ":android.security.flags-aconfig-java{.generated_srcjars}",
":com.android.hardware.camera2-aconfig-java{.generated_srcjars}",
":com.android.window.flags.window-aconfig-java{.generated_srcjars}",
+ ":com.android.hardware.input-aconfig-java{.generated_srcjars}",
":com.android.text.flags-aconfig-java{.generated_srcjars}",
],
+ // Add aconfig-annotations-lib as a dependency for the optimization
+ libs: ["aconfig-annotations-lib"],
}
// Default flags for java_aconfig_libraries that go into framework-minus-apex
@@ -58,6 +62,19 @@
defaults: ["framework-minus-apex-aconfig-java-defaults"],
}
+// Input
+aconfig_declarations {
+ name: "com.android.hardware.input.input-aconfig",
+ package: "com.android.hardware.input",
+ srcs: ["core/java/android/hardware/input/*.aconfig"],
+}
+
+java_aconfig_library {
+ name: "com.android.hardware.input-aconfig-java",
+ aconfig_declarations: "com.android.hardware.input.input-aconfig",
+ defaults: ["framework-minus-apex-aconfig-java-defaults"],
+}
+
// Text
aconfig_declarations {
name: "com.android.text.flags-aconfig",
@@ -70,3 +87,24 @@
aconfig_declarations: "com.android.text.flags-aconfig",
defaults: ["framework-minus-apex-aconfig-java-defaults"],
}
+
+// Security
+aconfig_declarations {
+ name: "android.security.flags-aconfig",
+ package: "android.security",
+ srcs: ["core/java/android/security/*.aconfig"],
+}
+
+java_aconfig_library {
+ name: "android.security.flags-aconfig-java",
+ aconfig_declarations: "android.security.flags-aconfig",
+ defaults: ["framework-minus-apex-aconfig-java-defaults"],
+}
+
+java_aconfig_library {
+ name: "android.security.flags-aconfig-java-host",
+ aconfig_declarations: "android.security.flags-aconfig",
+ host_supported: true,
+ test: true,
+ defaults: ["framework-minus-apex-aconfig-java-defaults"],
+}
diff --git a/cmds/app_process/app_main.cpp b/cmds/app_process/app_main.cpp
index a040b57..4e41f2c 100644
--- a/cmds/app_process/app_main.cpp
+++ b/cmds/app_process/app_main.cpp
@@ -271,9 +271,9 @@
} else if (strcmp(arg, "--application") == 0) {
application = true;
} else if (strncmp(arg, "--nice-name=", 12) == 0) {
- niceName.setTo(arg + 12);
+ niceName = (arg + 12);
} else if (strncmp(arg, "--", 2) != 0) {
- className.setTo(arg);
+ className = arg;
break;
} else {
--i;
diff --git a/cmds/bootanimation/BootAnimation.cpp b/cmds/bootanimation/BootAnimation.cpp
index 4690f33..fadf82a 100644
--- a/cmds/bootanimation/BootAnimation.cpp
+++ b/cmds/bootanimation/BootAnimation.cpp
@@ -1012,7 +1012,7 @@
return false;
}
- outString.setTo((char const*)entryMap->getDataPtr(), entryMap->getDataLength());
+ outString = String8((char const*)entryMap->getDataPtr(), entryMap->getDataLength());
delete entryMap;
return true;
}
@@ -1306,7 +1306,7 @@
part.audioData = (uint8_t *)map->getDataPtr();
part.audioLength = map->getDataLength();
} else if (leaf == "trim.txt") {
- part.trimData.setTo((char const*)map->getDataPtr(),
+ part.trimData = String8((char const*)map->getDataPtr(),
map->getDataLength());
} else {
Animation::Frame frame;
@@ -1396,7 +1396,7 @@
if (!exts) {
glGetError();
} else {
- gl_extensions.setTo(exts);
+ gl_extensions = exts;
if ((gl_extensions.find("GL_ARB_texture_non_power_of_two") != -1) ||
(gl_extensions.find("GL_OES_texture_npot") != -1)) {
mUseNpotTextures = true;
diff --git a/cmds/idmap2/libidmap2/CommandLineOptions.cpp b/cmds/idmap2/libidmap2/CommandLineOptions.cpp
index 8129d99..b1edc18 100644
--- a/cmds/idmap2/libidmap2/CommandLineOptions.cpp
+++ b/cmds/idmap2/libidmap2/CommandLineOptions.cpp
@@ -20,6 +20,7 @@
#include <cassert>
#include <iomanip>
#include <iostream>
+#include <iterator>
#include <memory>
#include <set>
#include <sstream>
diff --git a/core/java/android/hardware/input/input_framework.aconfig b/core/java/android/hardware/input/input_framework.aconfig
new file mode 100644
index 0000000..ebfe66f5
--- /dev/null
+++ b/core/java/android/hardware/input/input_framework.aconfig
@@ -0,0 +1,19 @@
+package: "com.android.hardware.input"
+
+# Project link: https://gantry.corp.google.com/projects/android_platform_input_native/changes
+
+flag {
+ namespace: "input_native"
+ name: "keyboard_layout_preview_flag"
+ description: "Controls whether a preview will be shown in Settings when selecting a physical keyboard layout"
+ bug: "293579375"
+}
+
+
+flag {
+ namespace: "input_native"
+ name: "keyboard_a11y_sticky_keys_flag"
+ description: "Controls if the sticky keys accessibility feature for physical keyboard is available to the user"
+ bug: "294546335"
+}
+
diff --git a/core/java/android/security/flags.aconfig b/core/java/android/security/flags.aconfig
new file mode 100644
index 0000000..b6c2b83
--- /dev/null
+++ b/core/java/android/security/flags.aconfig
@@ -0,0 +1,15 @@
+package: "android.security"
+
+flag {
+ name: "fsverity_api"
+ namespace: "hardware_backed_security"
+ description: "Feature flag for fs-verity API"
+ bug: "285185747"
+}
+
+flag {
+ name: "fix_unlocked_device_required_keys"
+ namespace: "hardware_backed_security"
+ description: "Fix bugs in behavior of UnlockedDeviceRequired keystore keys"
+ bug: "296464083"
+}
diff --git a/core/java/com/android/internal/policy/DecorView.java b/core/java/com/android/internal/policy/DecorView.java
index f998a69..e2a0c49 100644
--- a/core/java/com/android/internal/policy/DecorView.java
+++ b/core/java/com/android/internal/policy/DecorView.java
@@ -2660,8 +2660,7 @@
@Override
public String toString() {
- return "DecorView@" + Integer.toHexString(this.hashCode()) + "["
- + getTitleSuffix(mWindow.getAttributes()) + "]";
+ return super.toString() + "[" + getTitleSuffix(mWindow.getAttributes()) + "]";
}
private static class ColorViewState {
diff --git a/core/jni/android_database_CursorWindow.cpp b/core/jni/android_database_CursorWindow.cpp
index 60da2c2..c0e9215 100644
--- a/core/jni/android_database_CursorWindow.cpp
+++ b/core/jni/android_database_CursorWindow.cpp
@@ -89,7 +89,7 @@
CursorWindow* window;
const char* nameStr = env->GetStringUTFChars(nameObj, NULL);
- name.setTo(nameStr);
+ name = nameStr;
env->ReleaseStringUTFChars(nameObj, nameStr);
if (cursorWindowSize < 0) {
diff --git a/core/tests/coretests/src/android/hardware/input/InputFlagsTest.java b/core/tests/coretests/src/android/hardware/input/InputFlagsTest.java
new file mode 100644
index 0000000..5aeab42
--- /dev/null
+++ b/core/tests/coretests/src/android/hardware/input/InputFlagsTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2023 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 android.hardware.input;
+
+import static com.android.hardware.input.Flags.keyboardA11yStickyKeysFlag;
+import static com.android.hardware.input.Flags.keyboardLayoutPreviewFlag;
+
+import android.platform.test.annotations.Presubmit;
+
+import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * Tests for {@link com.android.hardware.input.Flags}
+ *
+ * Build/Install/Run:
+ * atest FrameworksCoreTests:InputFlagsTest
+ */
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+@Presubmit
+public class InputFlagsTest {
+
+ /**
+ * Test that the flags work
+ */
+ @Test
+ public void testFlags() {
+ // No crash when accessing the flag.
+ keyboardLayoutPreviewFlag();
+ keyboardA11yStickyKeysFlag();
+ }
+}
+
diff --git a/libs/androidfw/Android.bp b/libs/androidfw/Android.bp
index c80fb18..86e1fe3d 100644
--- a/libs/androidfw/Android.bp
+++ b/libs/androidfw/Android.bp
@@ -80,7 +80,10 @@
export_include_dirs: ["include"],
export_shared_lib_headers: ["libz"],
static_libs: ["libincfs-utils"],
- whole_static_libs: ["libincfs-utils"],
+ whole_static_libs: [
+ "libandroidfw_pathutils",
+ "libincfs-utils",
+ ],
export_static_lib_headers: ["libincfs-utils"],
target: {
android: {
@@ -132,6 +135,28 @@
},
}
+cc_library_static {
+ name: "libandroidfw_pathutils",
+ defaults: ["libandroidfw_defaults"],
+ host_supported: true,
+ export_include_dirs: ["include_pathutils"],
+ srcs: [
+ "PathUtils.cpp",
+ ],
+ shared_libs: [
+ "libutils",
+ ],
+ target: {
+ windows: {
+ enabled: true,
+ },
+ },
+ visibility: [
+ ":__subpackages__",
+ "//frameworks/base/tools/aapt",
+ ],
+}
+
common_test_libs = [
"libandroidfw",
"libbase",
diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp
index 795bb3c..fd6e18e 100644
--- a/libs/androidfw/AssetManager.cpp
+++ b/libs/androidfw/AssetManager.cpp
@@ -26,6 +26,7 @@
#include <androidfw/AssetDir.h>
#include <androidfw/AssetManager.h>
#include <androidfw/misc.h>
+#include <androidfw/PathUtils.h>
#include <androidfw/ResourceTypes.h>
#include <androidfw/ZipFileRO.h>
#include <cutils/atomic.h>
@@ -88,7 +89,7 @@
const char* root = getenv("ANDROID_DATA");
LOG_ALWAYS_FATAL_IF(root == NULL, "ANDROID_DATA not set");
String8 path(root);
- path.appendPath(kResourceCache);
+ appendPath(path, kResourceCache);
char buf[256]; // 256 chars should be enough for anyone...
strncpy(buf, pkgPath.c_str(), 255);
@@ -104,7 +105,7 @@
}
++p;
}
- path.appendPath(filename);
+ appendPath(path, filename);
path.append("@idmap");
return path;
@@ -181,7 +182,7 @@
String8 realPath(path);
if (kAppZipName) {
- realPath.appendPath(kAppZipName);
+ appendPath(realPath, kAppZipName);
}
ap.type = ::getFileType(realPath.c_str());
if (ap.type == kFileTypeRegular) {
@@ -367,7 +368,7 @@
LOG_ALWAYS_FATAL_IF(root == NULL, "ANDROID_ROOT not set");
String8 path(root);
- path.appendPath(kSystemAssets);
+ appendPath(path, kSystemAssets);
return addAssetPath(path, NULL, false /* appAsLib */, true /* isSystemAsset */);
}
@@ -439,7 +440,7 @@
LOG_FATAL_IF(mAssetPaths.size() == 0, "No assets added to AssetManager");
String8 assetName(kAssetsRoot);
- assetName.appendPath(fileName);
+ appendPath(assetName, fileName);
/*
* For each top-level asset path, search for the asset.
@@ -587,8 +588,8 @@
const char* data = getenv("ANDROID_DATA");
LOG_ALWAYS_FATAL_IF(data == NULL, "ANDROID_DATA not set");
String8 overlaysListPath(data);
- overlaysListPath.appendPath(kResourceCache);
- overlaysListPath.appendPath("overlays.list");
+ appendPath(overlaysListPath, kResourceCache);
+ appendPath(overlaysListPath, "overlays.list");
addSystemOverlays(overlaysListPath.c_str(), ap.path, sharedRes, nextEntryIdx);
#endif
sharedRes = const_cast<AssetManager*>(this)->
@@ -789,7 +790,7 @@
/* look at the filesystem on disk */
if (ap.type == kFileTypeDirectory) {
String8 path(ap.path);
- path.appendPath(fileName);
+ appendPath(path, fileName);
pAsset = openAssetFromFileLocked(path, mode);
@@ -841,9 +842,9 @@
sourceName.append(zipFileName);
sourceName.append(":");
if (dirName.length() > 0) {
- sourceName.appendPath(dirName);
+ appendPath(sourceName, dirName);
}
- sourceName.appendPath(fileName);
+ appendPath(sourceName, fileName);
return sourceName;
}
@@ -853,7 +854,7 @@
String8 AssetManager::createPathNameLocked(const asset_path& ap, const char* rootDir)
{
String8 path(ap.path);
- if (rootDir != NULL) path.appendPath(rootDir);
+ if (rootDir != NULL) appendPath(path, rootDir);
return path;
}
@@ -897,7 +898,7 @@
{
Asset* pAsset = NULL;
- if (strcasecmp(pathName.getPathExtension().c_str(), ".gz") == 0) {
+ if (strcasecmp(getPathExtension(pathName).c_str(), ".gz") == 0) {
//printf("TRYING '%s'\n", (const char*) pathName);
pAsset = Asset::createFromCompressedFile(pathName.c_str(), mode);
} else {
@@ -1078,8 +1079,7 @@
//printf("scanAndMergeDir: %s %s %s\n", ap.path.c_str(), rootDir, dirName);
String8 path = createPathNameLocked(ap, rootDir);
- if (dirName[0] != '\0')
- path.appendPath(dirName);
+ if (dirName[0] != '\0') appendPath(path, dirName);
SortedVector<AssetDir::FileInfo>* pContents = scanDirLocked(path);
if (pContents == NULL)
@@ -1176,7 +1176,7 @@
fileType = kFileTypeUnknown;
#else
// stat the file
- fileType = ::getFileType(path.appendPathCopy(entry->d_name).c_str());
+ fileType = ::getFileType(appendPathCopy(path, entry->d_name).c_str());
#endif
if (fileType != kFileTypeRegular && fileType != kFileTypeDirectory)
@@ -1184,9 +1184,9 @@
AssetDir::FileInfo info;
info.set(String8(entry->d_name), fileType);
- if (strcasecmp(info.getFileName().getPathExtension().c_str(), ".gz") == 0)
- info.setFileName(info.getFileName().getBasePath());
- info.setSourceName(path.appendPathCopy(info.getFileName()));
+ if (strcasecmp(getPathExtension(info.getFileName()).c_str(), ".gz") == 0)
+ info.setFileName(getBasePath(info.getFileName()));
+ info.setSourceName(appendPathCopy(path, info.getFileName()));
pContents->add(info);
}
@@ -1220,7 +1220,7 @@
/* convert "sounds" to "rootDir/sounds" */
if (rootDir != NULL) dirName = rootDir;
- dirName.appendPath(baseDirName);
+ appendPath(dirName, baseDirName);
/*
* Scan through the list of files, looking for a match. The files in
@@ -1269,7 +1269,7 @@
if (nextSlash == NULL) {
/* this is a file in the requested directory */
- info.set(String8(nameBuf).getPathLeaf(), kFileTypeRegular);
+ info.set(getPathLeaf(String8(nameBuf)), kFileTypeRegular);
info.setSourceName(
createZipSourceNameLocked(zipName, dirName, info.getFileName()));
diff --git a/libs/androidfw/BackupHelpers.cpp b/libs/androidfw/BackupHelpers.cpp
index 3582609..1a6a952 100644
--- a/libs/androidfw/BackupHelpers.cpp
+++ b/libs/androidfw/BackupHelpers.cpp
@@ -30,6 +30,7 @@
#include <utime.h>
#include <zlib.h>
+#include <androidfw/PathUtils.h>
#include <log/log.h>
#include <utils/ByteOrder.h>
#include <utils/KeyedVector.h>
@@ -606,14 +607,14 @@
prefix += packageName;
}
if (domain.length() > 0) {
- prefix.appendPath(domain);
+ appendPath(prefix, domain);
}
// pax extended means we don't put in a prefix field, and put a different
// string in the basic name field. We can also construct the full path name
// out of the substrings we've now built.
fullname = prefix;
- fullname.appendPath(relpath);
+ appendPath(fullname, relpath);
// ustar:
// [ 0 : 100 ]; file name/path
@@ -654,7 +655,7 @@
// Now build the pax *header* templated on the ustar header
memcpy(paxHeader, buf, 512);
- String8 leaf = fullname.getPathLeaf();
+ String8 leaf = getPathLeaf(fullname);
memset(paxHeader, 0, 100); // rewrite the name area
snprintf(paxHeader, 100, "PaxHeader/%s", leaf.c_str());
memset(paxHeader + 345, 0, 155); // rewrite the prefix area
diff --git a/libs/androidfw/PathUtils.cpp b/libs/androidfw/PathUtils.cpp
new file mode 100644
index 0000000..df7a9f0
--- /dev/null
+++ b/libs/androidfw/PathUtils.cpp
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+#include <androidfw/PathUtils.h>
+
+#include <utils/Compat.h>
+
+namespace android {
+
+String8 getPathLeaf(const String8& str) {
+ const char* cp;
+ const char*const buf = str.c_str();
+
+ cp = strrchr(buf, OS_PATH_SEPARATOR);
+ if (cp == nullptr)
+ return str;
+ else
+ return String8(cp+1);
+}
+
+String8 getPathDir(const String8& str8) {
+ const char* cp;
+ const char*const str = str8.c_str();
+
+ cp = strrchr(str, OS_PATH_SEPARATOR);
+ if (cp == nullptr)
+ return String8();
+ else
+ return String8(str, cp - str);
+}
+
+static char* findExtension(const String8& str8) {
+ const char* lastSlash;
+ const char* lastDot;
+ const char* const str = str8.c_str();
+
+ // only look at the filename
+ lastSlash = strrchr(str, OS_PATH_SEPARATOR);
+ if (lastSlash == nullptr)
+ lastSlash = str;
+ else
+ lastSlash++;
+
+ // find the last dot
+ lastDot = strrchr(lastSlash, '.');
+ if (lastDot == nullptr)
+ return nullptr;
+
+ // looks good, ship it
+ return const_cast<char*>(lastDot);
+}
+
+String8 getPathExtension(const String8& str) {
+ char* ext;
+
+ ext = findExtension(str);
+ if (ext != nullptr)
+ return String8(ext);
+ else
+ return String8();
+}
+
+String8 getBasePath(const String8& str8) {
+ char* ext;
+ const char* const str = str8.c_str();
+
+ ext = findExtension(str8);
+ if (ext == nullptr)
+ return str8;
+ else
+ return String8(str, ext - str);
+}
+
+static void setPathName(String8& s, const char* name) {
+ size_t len = strlen(name);
+ char* buf = s.lockBuffer(len);
+
+ memcpy(buf, name, len);
+
+ // remove trailing path separator, if present
+ if (len > 0 && buf[len - 1] == OS_PATH_SEPARATOR) len--;
+ buf[len] = '\0';
+
+ s.unlockBuffer(len);
+}
+
+String8& appendPath(String8& str, const char* name) {
+ // TODO: The test below will fail for Win32 paths. Fix later or ignore.
+ if (name[0] != OS_PATH_SEPARATOR) {
+ if (*name == '\0') {
+ // nothing to do
+ return str;
+ }
+
+ size_t len = str.length();
+ if (len == 0) {
+ // no existing filename, just use the new one
+ setPathName(str, name);
+ return str;
+ }
+
+ // make room for oldPath + '/' + newPath
+ int newlen = strlen(name);
+
+ char* buf = str.lockBuffer(len+1+newlen);
+
+ // insert a '/' if needed
+ if (buf[len-1] != OS_PATH_SEPARATOR)
+ buf[len++] = OS_PATH_SEPARATOR;
+
+ memcpy(buf+len, name, newlen+1);
+ len += newlen;
+
+ str.unlockBuffer(len);
+ return str;
+ } else {
+ setPathName(str, name);
+ return str;
+ }
+}
+
+} // namespace android
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp
index 0e7d841..cc38062 100644
--- a/libs/androidfw/ResourceTypes.cpp
+++ b/libs/androidfw/ResourceTypes.cpp
@@ -6190,13 +6190,13 @@
if (append) {
outString->append(tmp);
} else {
- outString->setTo(tmp);
+ *outString = tmp;
}
} else {
if (append) {
outString->append(String16(s, len));
} else {
- outString->setTo(s, len);
+ *outString = String16(s, len);
}
}
@@ -7398,10 +7398,10 @@
*pOverlayCrc = dtohl(map[3]);
}
if (pTargetPath) {
- pTargetPath->setTo(reinterpret_cast<const char*>(map + 4));
+ *pTargetPath = reinterpret_cast<const char*>(map + 4);
}
if (pOverlayPath) {
- pOverlayPath->setTo(reinterpret_cast<const char*>(map + 4 + 256 / sizeof(uint32_t)));
+ *pOverlayPath = reinterpret_cast<const char*>(map + 4 + 256 / sizeof(uint32_t));
}
return true;
}
diff --git a/libs/androidfw/include_pathutils/androidfw/PathUtils.h b/libs/androidfw/include_pathutils/androidfw/PathUtils.h
new file mode 100644
index 0000000..4debe8d
--- /dev/null
+++ b/libs/androidfw/include_pathutils/androidfw/PathUtils.h
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2023 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.
+ */
+
+#pragma once
+
+#include <utils/String8.h>
+
+/* This library contains path manipulation functions that are used only by androidfw and aapt.
+ * When it's possible, migrate all uses to std::filesystem::path.
+ */
+
+namespace android {
+
+/**
+ * Get just the filename component.
+ *
+ * DEPRECATED: use std::filesystem::path::filename
+ *
+ * "/tmp/foo/bar.c" --> "bar.c"
+ */
+String8 getPathLeaf(const String8& str);
+
+/**
+ * Remove the last (file name) component, leaving just the directory
+ * name.
+ *
+ * DEPRECATED: use std::filesystem::path::parent_path
+ *
+ * "/tmp/foo/bar.c" --> "/tmp/foo"
+ * "/tmp" --> "" // ????? shouldn't this be "/" ???? XXX
+ * "bar.c" --> ""
+ */
+String8 getPathDir(const String8& str);
+
+/**
+ * Return the filename extension. This is the last '.' and any number
+ * of characters that follow it. The '.' is included in case we
+ * decide to expand our definition of what constitutes an extension.
+ *
+ * DEPRECATED: use std::filesystem::path::extension
+ *
+ * "/tmp/foo/bar.c" --> ".c"
+ * "/tmp" --> ""
+ * "/tmp/foo.bar/baz" --> ""
+ * "foo.jpeg" --> ".jpeg"
+ * "foo." --> ""
+ */
+String8 getPathExtension(const String8& str);
+
+/**
+ * Return the path without the extension. Rules for what constitutes
+ * an extension are described in the comment for getPathExtension().
+ *
+ * DEPRECATED: use std::filesystem::path::stem and std::filesystem::path::parent_path
+ *
+ * "/tmp/foo/bar.c" --> "/tmp/foo/bar"
+ */
+String8 getBasePath(const String8& str);
+
+/**
+ * Add a component to the pathname. We guarantee that there is
+ * exactly one path separator between the old path and the new.
+ * If there is no existing name, we just copy the new name in.
+ *
+ * DEPRECATED: use std::filesystem::path::operator/=
+ *
+ * If leaf is a fully qualified path (i.e. starts with '/', it
+ * replaces whatever was there before.
+ */
+String8& appendPath(String8& str, const char* leaf);
+inline String8& appendPath(String8& str, const String8& leaf) {
+ return appendPath(str, leaf.c_str());
+}
+
+/**
+ * Like appendPath(), but does not affect this string. Returns a new one instead.
+ *
+ * DEPRECATED: use std::filesystem::operator/
+ */
+inline String8 appendPathCopy(String8 str, const char* leaf) { return appendPath(str, leaf); }
+inline String8 appendPathCopy(String8 str, const String8& leaf) {
+ return appendPath(str, leaf.c_str());
+}
+
+} // namespace android
diff --git a/libs/hwui/RenderNode.h b/libs/hwui/RenderNode.h
index 7092e17..208dc3e 100644
--- a/libs/hwui/RenderNode.h
+++ b/libs/hwui/RenderNode.h
@@ -121,9 +121,9 @@
if (name) {
const char* lastPeriod = strrchr(name, '.');
if (lastPeriod) {
- mName.setTo(lastPeriod + 1);
+ mName = (lastPeriod + 1);
} else {
- mName.setTo(name);
+ mName = name;
}
}
}
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 1583a1b..fb712bb 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -4580,7 +4580,9 @@
synchronized (this) {
while (!mQuit) {
final long timeToWait = timeOutTime - java.lang.System.currentTimeMillis();
- if (timeToWait < 0) { break; }
+ if (timeToWait <= 0) {
+ break;
+ }
this.wait(timeToWait);
}
}
diff --git a/packages/EncryptedLocalTransport/Android.bp b/packages/EncryptedLocalTransport/Android.bp
index 09e5630..9ae6d96 100644
--- a/packages/EncryptedLocalTransport/Android.bp
+++ b/packages/EncryptedLocalTransport/Android.bp
@@ -27,9 +27,6 @@
name: "EncryptedLocalTransport",
defaults: ["platform_app_defaults"],
srcs: ["src/**/*.java"],
- optimize: {
- proguard_flags_files: ["proguard.flags"],
- },
static_libs: ["LocalTransport"],
platform_apis: true,
certificate: "platform",
diff --git a/packages/EncryptedLocalTransport/proguard.flags b/packages/EncryptedLocalTransport/proguard.flags
deleted file mode 100644
index e4ce3c5..0000000
--- a/packages/EncryptedLocalTransport/proguard.flags
+++ /dev/null
@@ -1,2 +0,0 @@
--keep class com.android.localTransport.EncryptedLocalTransport
--keep class com.android.localTransport.EncryptedLocalTransportService
diff --git a/packages/Keyguard/proguard.flags b/packages/Keyguard/proguard.flags
deleted file mode 100644
index fb74b64..0000000
--- a/packages/Keyguard/proguard.flags
+++ /dev/null
@@ -1,27 +0,0 @@
--keep public class * {
- public void setBackgroundAlpha(float);
- public float getBackgroundAlpha();
- public void setContentAlpha(float);
- public float getContentAlpha();
- public void setAlpha(float);
- public float getAlpha();
- public void setAlpha(int);
- public int getAlpha();
- public void setRotationX(float);
- public float getRotationX();
- public void setRotationY(float);
- public float getRotationY();
- public void setPivotX(float);
- public float getPivotX();
- public void setPivotY(float);
- public float getPivotY();
- public void setScaleX(float);
- public float getScaleX();
- public void setScaleY(float);
- public float getScaleY();
- public void setTranslationX(float);
- public float getTranslationX();
- public void setTranslationY(float);
- public float getTranslationY();
-}
-
diff --git a/packages/LocalTransport/Android.bp b/packages/LocalTransport/Android.bp
index d4fa191..e7a273b 100644
--- a/packages/LocalTransport/Android.bp
+++ b/packages/LocalTransport/Android.bp
@@ -27,9 +27,7 @@
name: "LocalTransport",
defaults: ["platform_app_defaults"],
srcs: ["src/**/*.java"],
- optimize: {
- proguard_flags_files: ["proguard.flags"],
- },
+ libs: ["keepanno-annotations"],
platform_apis: true,
certificate: "platform",
privileged: true,
diff --git a/packages/LocalTransport/proguard.flags b/packages/LocalTransport/proguard.flags
deleted file mode 100644
index c1f51b8..0000000
--- a/packages/LocalTransport/proguard.flags
+++ /dev/null
@@ -1,5 +0,0 @@
--keep class com.android.localTransport.LocalTransport
--keep class com.android.localTransport.LocalTransportParameters
--keep class com.android.localTransport.LocalTransportService
-
-
diff --git a/packages/LocalTransport/src/com/android/localtransport/LocalTransport.java b/packages/LocalTransport/src/com/android/localtransport/LocalTransport.java
index 4344e94..6540cc0 100644
--- a/packages/LocalTransport/src/com/android/localtransport/LocalTransport.java
+++ b/packages/LocalTransport/src/com/android/localtransport/LocalTransport.java
@@ -35,6 +35,9 @@
import android.util.Base64;
import android.util.Log;
+import com.android.tools.r8.keepanno.annotations.KeepTarget;
+import com.android.tools.r8.keepanno.annotations.UsesReflection;
+
import libcore.io.IoUtils;
import java.io.BufferedOutputStream;
@@ -122,6 +125,13 @@
return mParameters;
}
+
+ @UsesReflection({
+ // As the runtime class name is used to generate the returned name, and the returned
+ // name may be used used with reflection, generate the necessary keep rules.
+ @KeepTarget(classConstant = LocalTransport.class),
+ @KeepTarget(extendsClassConstant = LocalTransport.class)
+ })
@Override
public String name() {
return new ComponentName(mContext, this.getClass()).flattenToShortString();
diff --git a/packages/SharedStorageBackup/Android.bp b/packages/SharedStorageBackup/Android.bp
index 21516fa..225b5b4 100644
--- a/packages/SharedStorageBackup/Android.bp
+++ b/packages/SharedStorageBackup/Android.bp
@@ -27,9 +27,6 @@
name: "SharedStorageBackup",
defaults: ["platform_app_defaults"],
srcs: ["src/**/*.java"],
- optimize: {
- proguard_flags_files: ["proguard.flags"],
- },
platform_apis: true,
certificate: "platform",
privileged: true,
diff --git a/packages/SharedStorageBackup/proguard.flags b/packages/SharedStorageBackup/proguard.flags
deleted file mode 100644
index 6a66a47..0000000
--- a/packages/SharedStorageBackup/proguard.flags
+++ /dev/null
@@ -1,2 +0,0 @@
--keep class com.android.sharedstoragebackup.SharedStorageAgent
--keep class com.android.sharedstoragebackup.ObbBackupService
diff --git a/packages/SystemUI/OWNERS b/packages/SystemUI/OWNERS
index 0cd8b45..5b2409a 100644
--- a/packages/SystemUI/OWNERS
+++ b/packages/SystemUI/OWNERS
@@ -6,6 +6,7 @@
aaliomer@google.com
aaronjli@google.com
+achalke@google.com
acul@google.com
adamcohen@google.com
aioana@google.com
@@ -72,6 +73,7 @@
patmanning@google.com
peanutbutter@google.com
peskal@google.com
+petrcermak@google.com
pinyaoting@google.com
pixel@google.com
pomini@google.com
@@ -83,14 +85,17 @@
shanh@google.com
snoeberger@google.com
steell@google.com
+stevenckng@google.com
stwu@google.com
syeonlee@google.com
sunnygoyal@google.com
thiruram@google.com
+tkachenkoi@google.com
tracyzhou@google.com
tsuji@google.com
twickham@google.com
vadimt@google.com
+vanjan@google.com
victortulias@google.com
winsonc@google.com
wleshner@google.com
diff --git a/packages/WallpaperBackup/Android.bp b/packages/WallpaperBackup/Android.bp
index d142f25..840e99a 100644
--- a/packages/WallpaperBackup/Android.bp
+++ b/packages/WallpaperBackup/Android.bp
@@ -27,9 +27,6 @@
name: "WallpaperBackup",
defaults: ["platform_app_defaults"],
srcs: ["src/**/*.java"],
- optimize: {
- proguard_flags_files: ["proguard.flags"],
- },
platform_apis: true,
certificate: "platform",
privileged: false,
diff --git a/packages/WallpaperBackup/proguard.flags b/packages/WallpaperBackup/proguard.flags
deleted file mode 100644
index 247e6ef..0000000
--- a/packages/WallpaperBackup/proguard.flags
+++ /dev/null
@@ -1 +0,0 @@
--keep class com.android.wallpaperbackup.WallpaperBackupAgent
diff --git a/services/core/java/com/android/server/am/OWNERS b/services/core/java/com/android/server/am/OWNERS
index ef15beb..bf7cc10 100644
--- a/services/core/java/com/android/server/am/OWNERS
+++ b/services/core/java/com/android/server/am/OWNERS
@@ -32,7 +32,7 @@
per-file *Assist* = file:/core/java/android/service/voice/OWNERS
per-file *Voice* = file:/core/java/android/service/voice/OWNERS
-per-file SettingsToPropertiesMapper.java = omakoto@google.com, yamasani@google.com
+per-file SettingsToPropertiesMapper.java = omakoto@google.com, yamasani@google.com, dzshen@google.com, zhidou@google.com, tedbauer@google.com
per-file CarUserSwitchingDialog.java = file:platform/packages/services/Car:/OWNERS
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index bfccd58..53fbe8f 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -1741,6 +1741,7 @@
.setBypassableVpn(bypassable)
.setVpnRequiresValidation(mConfig.requiresInternetValidation)
.setLocalRoutesExcludedForVpn(mConfig.excludeLocalRoutes)
+ .setLegacyExtraInfo("VPN:" + mPackage)
.build();
capsBuilder.setOwnerUid(mOwnerUID);
diff --git a/services/core/java/com/android/server/security/OWNERS b/services/core/java/com/android/server/security/OWNERS
index 5bcc98b6..fa4bf22 100644
--- a/services/core/java/com/android/server/security/OWNERS
+++ b/services/core/java/com/android/server/security/OWNERS
@@ -1,4 +1,7 @@
# Bug component: 36824
+include /core/java/android/security/OWNERS
+
per-file *AttestationVerification* = file:/core/java/android/security/attestationverification/OWNERS
per-file FileIntegrity*.java = victorhsieh@google.com
+per-file KeyChainSystemService.java = file:platform/packages/apps/KeyChain:/OWNERS
diff --git a/services/core/java/com/android/server/trust/TrustAgentWrapper.java b/services/core/java/com/android/server/trust/TrustAgentWrapper.java
index 86eb36c93..23cb91d 100644
--- a/services/core/java/com/android/server/trust/TrustAgentWrapper.java
+++ b/services/core/java/com/android/server/trust/TrustAgentWrapper.java
@@ -49,6 +49,7 @@
import android.util.Slog;
import com.android.internal.infra.AndroidFuture;
+import com.android.server.utils.Slogf;
import java.util.Collections;
import java.util.List;
@@ -318,8 +319,8 @@
int flags,
AndroidFuture resultCallback) {
if (DEBUG) {
- Slog.d(TAG, "enableTrust(" + message + ", durationMs = " + durationMs
- + ", flags = " + flags + ")");
+ Slogf.d(TAG, "grantTrust(message=\"%s\", durationMs=%d, flags=0x%x)",
+ message, durationMs, flags);
}
Message msg = mHandler.obtainMessage(
@@ -336,30 +337,32 @@
@Override
public void lockUser() {
+ if (DEBUG) Slog.d(TAG, "lockUser()");
mHandler.sendEmptyMessage(MSG_LOCK_USER);
}
@Override
public void setManagingTrust(boolean managingTrust) {
- if (DEBUG) Slog.d(TAG, "managingTrust()");
+ if (DEBUG) Slogf.d(TAG, "setManagingTrust(%s)", managingTrust);
mHandler.obtainMessage(MSG_MANAGING_TRUST, managingTrust ? 1 : 0, 0).sendToTarget();
}
@Override
public void onConfigureCompleted(boolean result, IBinder token) {
- if (DEBUG) Slog.d(TAG, "onSetTrustAgentFeaturesEnabledCompleted(result=" + result);
+ if (DEBUG) Slogf.d(TAG, "onConfigureCompleted(result=%s)", result);
mHandler.obtainMessage(MSG_SET_TRUST_AGENT_FEATURES_COMPLETED,
result ? 1 : 0, 0, token).sendToTarget();
}
@Override
public void addEscrowToken(byte[] token, int userId) {
+ // 'token' is secret; never log it.
+ if (DEBUG) Slogf.d(TAG, "addEscrowToken(userId=%d)", userId);
+
if (mContext.getResources()
.getBoolean(com.android.internal.R.bool.config_allowEscrowTokenForTrustAgent)) {
- throw new SecurityException("Escrow token API is not allowed.");
+ throw new SecurityException("Escrow token API is not allowed.");
}
-
- if (DEBUG) Slog.d(TAG, "adding escrow token for user " + userId);
Message msg = mHandler.obtainMessage(MSG_ADD_ESCROW_TOKEN);
msg.getData().putByteArray(DATA_ESCROW_TOKEN, token);
msg.getData().putInt(DATA_USER_ID, userId);
@@ -368,12 +371,12 @@
@Override
public void isEscrowTokenActive(long handle, int userId) {
+ if (DEBUG) Slogf.d(TAG, "isEscrowTokenActive(handle=%016x, userId=%d)", handle, userId);
+
if (mContext.getResources()
.getBoolean(com.android.internal.R.bool.config_allowEscrowTokenForTrustAgent)) {
throw new SecurityException("Escrow token API is not allowed.");
}
-
- if (DEBUG) Slog.d(TAG, "checking the state of escrow token on user " + userId);
Message msg = mHandler.obtainMessage(MSG_ESCROW_TOKEN_STATE);
msg.getData().putLong(DATA_HANDLE, handle);
msg.getData().putInt(DATA_USER_ID, userId);
@@ -382,12 +385,12 @@
@Override
public void removeEscrowToken(long handle, int userId) {
+ if (DEBUG) Slogf.d(TAG, "removeEscrowToken(handle=%016x, userId=%d)", handle, userId);
+
if (mContext.getResources()
.getBoolean(com.android.internal.R.bool.config_allowEscrowTokenForTrustAgent)) {
throw new SecurityException("Escrow token API is not allowed.");
}
-
- if (DEBUG) Slog.d(TAG, "removing escrow token on user " + userId);
Message msg = mHandler.obtainMessage(MSG_REMOVE_ESCROW_TOKEN);
msg.getData().putLong(DATA_HANDLE, handle);
msg.getData().putInt(DATA_USER_ID, userId);
@@ -396,12 +399,13 @@
@Override
public void unlockUserWithToken(long handle, byte[] token, int userId) {
+ // 'token' is secret; never log it.
+ if (DEBUG) Slogf.d(TAG, "unlockUserWithToken(handle=%016x, userId=%d)", handle, userId);
+
if (mContext.getResources()
.getBoolean(com.android.internal.R.bool.config_allowEscrowTokenForTrustAgent)) {
throw new SecurityException("Escrow token API is not allowed.");
}
-
- if (DEBUG) Slog.d(TAG, "unlocking user " + userId);
Message msg = mHandler.obtainMessage(MSG_UNLOCK_USER);
msg.getData().putInt(DATA_USER_ID, userId);
msg.getData().putLong(DATA_HANDLE, handle);
@@ -411,7 +415,7 @@
@Override
public void showKeyguardErrorMessage(CharSequence message) {
- if (DEBUG) Slog.d(TAG, "Showing keyguard error message: " + message);
+ if (DEBUG) Slogf.d(TAG, "showKeyguardErrorMessage(\"%s\")", message);
Message msg = mHandler.obtainMessage(MSG_SHOW_KEYGUARD_ERROR_MESSAGE);
msg.getData().putCharSequence(DATA_MESSAGE, message);
msg.sendToTarget();
diff --git a/services/core/java/com/android/server/trust/TrustManagerService.java b/services/core/java/com/android/server/trust/TrustManagerService.java
index 04cd7f7..2ef82d7 100644
--- a/services/core/java/com/android/server/trust/TrustManagerService.java
+++ b/services/core/java/com/android/server/trust/TrustManagerService.java
@@ -158,10 +158,26 @@
private VirtualDeviceManagerInternal mVirtualDeviceManager;
private enum TrustState {
- UNTRUSTED, // the phone is not unlocked by any trustagents
- TRUSTABLE, // the phone is in a semi-locked state that can be unlocked if
- // FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE is passed and a trustagent is trusted
- TRUSTED // the phone is unlocked
+ // UNTRUSTED means that TrustManagerService is currently *not* giving permission for the
+ // user's Keyguard to be dismissed, and grants of trust by trust agents are remembered in
+ // the corresponding TrustAgentWrapper but are not recognized until the device is unlocked
+ // for the user. I.e., if the device is locked and the state is UNTRUSTED, it cannot be
+ // unlocked by a trust agent. Automotive devices are an exception; grants of trust are
+ // always recognized on them.
+ UNTRUSTED,
+
+ // TRUSTABLE is the same as UNTRUSTED except that new grants of trust using
+ // FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE are recognized for moving to TRUSTED. I.e., if
+ // the device is locked and the state is TRUSTABLE, it can be unlocked by a trust agent,
+ // provided that the trust agent chooses to use Active Unlock. The TRUSTABLE state is only
+ // possible as a result of a downgrade from TRUSTED, after a trust agent used
+ // FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE in its most recent grant.
+ TRUSTABLE,
+
+ // TRUSTED means that TrustManagerService is currently giving permission for the user's
+ // Keyguard to be dismissed. This implies that the device is unlocked for the user (where
+ // the case of Keyguard showing but dismissible just with swipe counts as "unlocked").
+ TRUSTED
};
@GuardedBy("mUserTrustState")
@@ -814,6 +830,12 @@
}
}
+ private TrustState getUserTrustStateInner(int userId) {
+ synchronized (mUserTrustState) {
+ return mUserTrustState.get(userId, TrustState.UNTRUSTED);
+ }
+ }
+
boolean isDeviceLockedInner(int userId) {
synchronized (mDeviceLockedForUser) {
return mDeviceLockedForUser.get(userId, true);
@@ -864,7 +886,12 @@
continue;
}
- boolean trusted = aggregateIsTrusted(id);
+ final boolean trusted;
+ if (android.security.Flags.fixUnlockedDeviceRequiredKeys()) {
+ trusted = getUserTrustStateInner(id) == TrustState.TRUSTED;
+ } else {
+ trusted = aggregateIsTrusted(id);
+ }
boolean showingKeyguard = true;
boolean biometricAuthenticated = false;
boolean currentUserIsUnlocked = false;
@@ -1628,7 +1655,7 @@
if (isCurrent) {
fout.print(" (current)");
}
- fout.print(": trusted=" + dumpBool(aggregateIsTrusted(user.id)));
+ fout.print(": trustState=" + getUserTrustStateInner(user.id));
fout.print(", trustManaged=" + dumpBool(aggregateIsTrustManaged(user.id)));
fout.print(", deviceLocked=" + dumpBool(isDeviceLockedInner(user.id)));
fout.print(", strongAuthRequired=" + dumpHex(
diff --git a/startop/apps/ColorChanging/app/build.gradle b/startop/apps/ColorChanging/app/build.gradle
index ab955aa..11b14c0 100644
--- a/startop/apps/ColorChanging/app/build.gradle
+++ b/startop/apps/ColorChanging/app/build.gradle
@@ -14,7 +14,7 @@
buildTypes {
release {
minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
}
}
}
diff --git a/startop/apps/ColorChanging/app/proguard-rules.pro b/startop/apps/ColorChanging/app/proguard-rules.pro
deleted file mode 100644
index f1b4245..0000000
--- a/startop/apps/ColorChanging/app/proguard-rules.pro
+++ /dev/null
@@ -1,21 +0,0 @@
-# Add project specific ProGuard rules here.
-# You can control the set of applied configuration files using the
-# proguardFiles setting in build.gradle.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# If your project uses WebView with JS, uncomment the following
-# and specify the fully qualified class name to the JavaScript interface
-# class:
-#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
-# public *;
-#}
-
-# Uncomment this to preserve the line number information for
-# debugging stack traces.
-#-keepattributes SourceFile,LineNumberTable
-
-# If you keep the line number information, uncomment this to
-# hide the original source file name.
-#-renamesourcefileattribute SourceFile
diff --git a/tests/TrustTests/Android.bp b/tests/TrustTests/Android.bp
index a1b888a..c216bce 100644
--- a/tests/TrustTests/Android.bp
+++ b/tests/TrustTests/Android.bp
@@ -25,6 +25,7 @@
"androidx.test.rules",
"androidx.test.ext.junit",
"androidx.test.uiautomator_uiautomator",
+ "flag-junit",
"mockito-target-minus-junit4",
"servicestests-utils",
"truth-prebuilt",
diff --git a/tests/TrustTests/src/android/trust/test/GrantAndRevokeTrustTest.kt b/tests/TrustTests/src/android/trust/test/GrantAndRevokeTrustTest.kt
index f864fed..1dfd5c0 100644
--- a/tests/TrustTests/src/android/trust/test/GrantAndRevokeTrustTest.kt
+++ b/tests/TrustTests/src/android/trust/test/GrantAndRevokeTrustTest.kt
@@ -16,6 +16,10 @@
package android.trust.test
+import android.content.pm.PackageManager
+import android.platform.test.annotations.RequiresFlagsDisabled
+import android.platform.test.annotations.RequiresFlagsEnabled
+import android.platform.test.flag.junit.DeviceFlagsValueProvider
import android.service.trust.GrantTrustResult
import android.trust.BaseTrustAgentService
import android.trust.TrustTestActivity
@@ -27,6 +31,7 @@
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
import androidx.test.uiautomator.UiDevice
import com.android.server.testutils.mock
+import org.junit.Assume.assumeFalse
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -45,6 +50,7 @@
private val activityScenarioRule = ActivityScenarioRule(TrustTestActivity::class.java)
private val lockStateTrackingRule = LockStateTrackingRule()
private val trustAgentRule = TrustAgentRule<GrantAndRevokeTrustAgent>()
+ private val packageManager = getInstrumentation().getTargetContext().getPackageManager()
@get:Rule
val rule: RuleChain = RuleChain
@@ -52,6 +58,7 @@
.around(ScreenLockRule())
.around(lockStateTrackingRule)
.around(trustAgentRule)
+ .around(DeviceFlagsValueProvider.createCheckFlagsRule())
@Before
fun manageTrust() {
@@ -72,7 +79,7 @@
trustAgentRule.agent.grantTrust(GRANT_MESSAGE, 10000, 0) {}
uiDevice.sleep()
- lockStateTrackingRule.assertUnlocked()
+ lockStateTrackingRule.assertUnlockedAndTrusted()
}
@Test
@@ -86,6 +93,51 @@
}
@Test
+ @RequiresFlagsEnabled(android.security.Flags.FLAG_FIX_UNLOCKED_DEVICE_REQUIRED_KEYS)
+ fun grantCannotActivelyUnlockDevice() {
+ // On automotive, trust agents can actively unlock the device.
+ assumeFalse(packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE))
+
+ // Lock the device.
+ uiDevice.sleep()
+ lockStateTrackingRule.assertLocked()
+
+ // Grant trust.
+ trustAgentRule.agent.grantTrust(GRANT_MESSAGE, 10000, 0) {}
+
+ // The grant should not have unlocked the device. Wait a bit so that
+ // TrustManagerService probably will have finished processing the grant.
+ await()
+ lockStateTrackingRule.assertLocked()
+
+ // Turn the screen on and off to cause TrustManagerService to refresh
+ // its deviceLocked state. Then verify the state is still locked. This
+ // part failed before the fix for b/296464083.
+ uiDevice.wakeUp()
+ uiDevice.sleep()
+ await()
+ lockStateTrackingRule.assertLocked()
+ }
+
+ @Test
+ @RequiresFlagsDisabled(android.security.Flags.FLAG_FIX_UNLOCKED_DEVICE_REQUIRED_KEYS)
+ fun grantCouldCauseWrongDeviceLockedStateDueToBug() {
+ // On automotive, trust agents can actively unlock the device.
+ assumeFalse(packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE))
+
+ // Verify that b/296464083 exists. That is, when the device is locked
+ // and a trust agent grants trust, the deviceLocked state incorrectly
+ // becomes false even though the device correctly remains locked.
+ uiDevice.sleep()
+ lockStateTrackingRule.assertLocked()
+ trustAgentRule.agent.grantTrust(GRANT_MESSAGE, 10000, 0) {}
+ uiDevice.wakeUp()
+ uiDevice.sleep()
+ await()
+ lockStateTrackingRule.assertUnlockedButNotReally()
+ }
+
+ @Test
fun grantDoesNotCallBack() {
val callback = mock<(GrantTrustResult) -> Unit>()
trustAgentRule.agent.grantTrust(GRANT_MESSAGE, 0, 0, callback)
diff --git a/tests/TrustTests/src/android/trust/test/TemporaryAndRenewableTrustTest.kt b/tests/TrustTests/src/android/trust/test/TemporaryAndRenewableTrustTest.kt
index ae72247..96362b8 100644
--- a/tests/TrustTests/src/android/trust/test/TemporaryAndRenewableTrustTest.kt
+++ b/tests/TrustTests/src/android/trust/test/TemporaryAndRenewableTrustTest.kt
@@ -102,7 +102,7 @@
trustAgentRule.agent.grantTrust(
GRANT_MESSAGE, 0, FLAG_GRANT_TRUST_TEMPORARY_AND_RENEWABLE) {}
- lockStateTrackingRule.assertUnlocked()
+ lockStateTrackingRule.assertUnlockedAndTrusted()
}
@Test
@@ -125,7 +125,7 @@
Log.i(TAG, "Callback received; status=${it.status}")
result = it
}
- lockStateTrackingRule.assertUnlocked()
+ lockStateTrackingRule.assertUnlockedAndTrusted()
wait("callback triggered") { result?.status == STATUS_UNLOCKED_BY_GRANT }
}
diff --git a/tests/TrustTests/src/android/trust/test/lib/LockStateTrackingRule.kt b/tests/TrustTests/src/android/trust/test/lib/LockStateTrackingRule.kt
index 1930a1c..583cfc7 100644
--- a/tests/TrustTests/src/android/trust/test/lib/LockStateTrackingRule.kt
+++ b/tests/TrustTests/src/android/trust/test/lib/LockStateTrackingRule.kt
@@ -16,6 +16,7 @@
package android.trust.test.lib
+import android.app.KeyguardManager
import android.app.trust.TrustManager
import android.app.trust.TrustManager.TrustListener
import android.content.Context
@@ -27,18 +28,23 @@
import org.junit.runners.model.Statement
/**
- * Rule for tracking the lock state of the device based on events emitted to [TrustListener].
+ * Rule for tracking the trusted state of the device based on events emitted to
+ * [TrustListener]. Provides helper methods for verifying that the trusted
+ * state has a particular value and is consistent with (a) the keyguard "locked"
+ * (i.e. showing) value when applicable, and (b) the device locked value that is
+ * tracked by TrustManagerService and is queryable via KeyguardManager.
*/
class LockStateTrackingRule : TestRule {
private val context: Context = getApplicationContext()
- private val windowManager = WindowManagerGlobal.getWindowManagerService()
+ private val windowManager = checkNotNull(WindowManagerGlobal.getWindowManagerService())
+ private val keyguardManager = context.getSystemService(KeyguardManager::class.java) as KeyguardManager
- @Volatile lateinit var lockState: LockState
+ @Volatile lateinit var trustState: TrustState
private set
override fun apply(base: Statement, description: Description) = object : Statement() {
override fun evaluate() {
- lockState = LockState(locked = windowManager.isKeyguardLocked)
+ trustState = TrustState()
val trustManager = context.getSystemService(TrustManager::class.java) as TrustManager
val listener = Listener()
@@ -52,12 +58,25 @@
}
fun assertLocked() {
- wait("un-locked per TrustListener") { lockState.locked == true }
- wait("keyguard lock") { windowManager.isKeyguardLocked }
+ wait("device locked") { keyguardManager.isDeviceLocked }
+ // isDeviceLocked implies isKeyguardLocked && !trusted.
+ wait("keyguard locked") { windowManager.isKeyguardLocked }
+ wait("not trusted") { trustState.trusted == false }
}
- fun assertUnlocked() {
- wait("locked per TrustListener") { lockState.locked == false }
+ // TODO(b/299298338) remove this when removing FLAG_FIX_UNLOCKED_DEVICE_REQUIRED_KEYS
+ fun assertUnlockedButNotReally() {
+ wait("device unlocked") { !keyguardManager.isDeviceLocked }
+ wait("not trusted") { trustState.trusted == false }
+ wait("keyguard locked") { windowManager.isKeyguardLocked }
+ }
+
+ fun assertUnlockedAndTrusted() {
+ wait("device unlocked") { !keyguardManager.isDeviceLocked }
+ wait("trusted") { trustState.trusted == true }
+ // Can't check for !isKeyguardLocked here, since isKeyguardLocked
+ // returns true in the case where the keyguard is dismissible with
+ // swipe, which is considered "device unlocked"!
}
inner class Listener : TrustListener {
@@ -69,7 +88,7 @@
trustGrantedMessages: MutableList<String>
) {
Log.d(TAG, "Device became trusted=$enabled")
- lockState = lockState.copy(locked = !enabled)
+ trustState = trustState.copy(trusted=enabled)
}
override fun onTrustManagedChanged(enabled: Boolean, userId: Int) {
@@ -79,8 +98,8 @@
}
}
- data class LockState(
- val locked: Boolean? = null
+ data class TrustState(
+ val trusted: Boolean? = null
)
companion object {
diff --git a/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt b/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt
index 4189baa..f1edca3 100644
--- a/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt
+++ b/tests/TrustTests/src/android/trust/test/lib/ScreenLockRule.kt
@@ -36,7 +36,7 @@
class ScreenLockRule : TestRule {
private val context: Context = getApplicationContext()
private val uiDevice = UiDevice.getInstance(getInstrumentation())
- private val windowManager = WindowManagerGlobal.getWindowManagerService()
+ private val windowManager = checkNotNull(WindowManagerGlobal.getWindowManagerService())
private val lockPatternUtils = LockPatternUtils(context)
private var instantLockSavedValue = false
diff --git a/tools/aapt/AaptAssets.cpp b/tools/aapt/AaptAssets.cpp
index 0fc2617..0aaf3e8 100644
--- a/tools/aapt/AaptAssets.cpp
+++ b/tools/aapt/AaptAssets.cpp
@@ -7,7 +7,9 @@
#include "AaptUtil.h"
#include "Main.h"
#include "ResourceFilter.h"
+#include "Utils.h"
+#include <androidfw/PathUtils.h>
#include <utils/misc.h>
#include <utils/SortedVector.h>
@@ -96,7 +98,7 @@
char *matchedPattern = NULL;
String8 fullPath(root);
- fullPath.appendPath(path);
+ appendPath(fullPath, String8(path));
FileType type = getFileType(fullPath);
int plen = strlen(path);
@@ -508,7 +510,7 @@
{
if (hasData()) {
String8 name(mGroupEntry.toDirName(String8()));
- name.appendPath(mPath);
+ appendPath(name, mPath);
name.append(" #generated");
return name;
}
@@ -615,7 +617,7 @@
String8 remain = path;
sp<AaptDir> subdir = this;
- while (name = remain.walkPath(&remain), remain != "") {
+ while (name = walkPath(remain, &remain), remain != "") {
subdir = subdir->makeDir(name);
}
@@ -623,7 +625,7 @@
if (i >= 0) {
return subdir->mDirs.valueAt(i);
}
- sp<AaptDir> dir = new AaptDir(name, subdir->mPath.appendPathCopy(name));
+ sp<AaptDir> dir = new AaptDir(name, appendPathCopy(subdir->mPath, name));
subdir->mDirs.add(name, dir);
return dir;
}
@@ -645,7 +647,7 @@
if (mFiles.indexOfKey(leafName) >= 0) {
group = mFiles.valueFor(leafName);
} else {
- group = new AaptGroup(leafName, mPath.appendPathCopy(leafName));
+ group = new AaptGroup(leafName, appendPathCopy(mPath, leafName));
mFiles.add(leafName, group);
}
@@ -684,7 +686,7 @@
// Add fully qualified path for dependency purposes
// if we're collecting them
if (fullResPaths != NULL) {
- fullResPaths->add(srcDir.appendPathCopy(name));
+ fullResPaths->add(appendPathCopy(srcDir, name));
}
}
closedir(dir);
@@ -701,7 +703,7 @@
String8 pathName(srcDir);
FileType type;
- pathName.appendPath(fileNames[i].c_str());
+ appendPath(pathName, fileNames[i]);
type = getFileType(pathName.c_str());
if (type == kFileTypeDirectory) {
sp<AaptDir> subdir;
@@ -709,7 +711,7 @@
if (mDirs.indexOfKey(fileNames[i]) >= 0) {
subdir = mDirs.valueFor(fileNames[i]);
} else {
- subdir = new AaptDir(fileNames[i], mPath.appendPathCopy(fileNames[i]));
+ subdir = new AaptDir(fileNames[i], appendPathCopy(mPath, fileNames[i]));
notAdded = true;
}
ssize_t res = subdir->slurpFullTree(bundle, pathName, kind,
@@ -821,11 +823,11 @@
{
if (mFiles.size() > 0) {
// Arbitrarily pull the first file out of the list as the source dir.
- return mFiles.valueAt(0)->getPrintableSource().getPathDir();
+ return getPathDir(mFiles.valueAt(0)->getPrintableSource());
}
if (mDirs.size() > 0) {
// Or arbitrarily pull the first dir out of the list as the source dir.
- return mDirs.valueAt(0)->getPrintableSource().getPathDir();
+ return getPathDir(mDirs.valueAt(0)->getPrintableSource());
}
// Should never hit this case, but to be safe...
@@ -908,8 +910,8 @@
sp<AaptFile> file;
String8 root, remain(filePath), partialPath;
while (remain.length() > 0) {
- root = remain.walkPath(&remain);
- partialPath.appendPath(root);
+ root = walkPath(remain, &remain);
+ appendPath(partialPath, root);
const String8 rootStr(root);
@@ -924,7 +926,7 @@
return NULL;
}
}
- file = new AaptFile(srcDir.appendPathCopy(filePath), entry, resType);
+ file = new AaptFile(appendPathCopy(srcDir, filePath), entry, resType);
status_t res = group->addFile(file);
if (res != NO_ERROR) {
return NULL;
@@ -981,7 +983,7 @@
if (bundle->getAndroidManifestFile() != NULL) {
// place at root of zip.
String8 srcFile(bundle->getAndroidManifestFile());
- addFile(srcFile.getPathLeaf(), AaptGroupEntry(), srcFile.getPathDir(),
+ addFile(getPathLeaf(srcFile), AaptGroupEntry(), getPathDir(srcFile),
NULL, String8());
totalCount++;
}
@@ -1154,7 +1156,7 @@
}
String8 subdirName(srcDir);
- subdirName.appendPath(entry->d_name);
+ appendPath(subdirName, entry->d_name);
AaptGroupEntry group;
String8 resType;
@@ -1239,16 +1241,16 @@
String8 entryName(entry->getFileName());
- String8 dirName = entryName.getPathDir();
+ String8 dirName = getPathDir(entryName);
sp<AaptDir> dir = dirName == "" ? this : makeDir(dirName);
String8 resType;
AaptGroupEntry kind;
String8 remain;
- if (entryName.walkPath(&remain) == kResourceDir) {
+ if (walkPath(entryName, &remain) == kResourceDir) {
// these are the resources, pull their type out of the directory name
- kind.initFromDirName(remain.walkPath().c_str(), &resType);
+ kind.initFromDirName(walkPath(remain).c_str(), &resType);
} else {
// these are untyped and don't have an AaptGroupEntry
}
@@ -1258,10 +1260,10 @@
}
// use the one from the zip file if they both exist.
- dir->removeFile(entryName.getPathLeaf());
+ dir->removeFile(getPathLeaf(entryName));
sp<AaptFile> file = new AaptFile(entryName, kind, resType);
- status_t err = dir->addLeafFile(entryName.getPathLeaf(), file);
+ status_t err = dir->addLeafFile(getPathLeaf(entryName), file);
if (err != NO_ERROR) {
fprintf(stderr, "err=%s entryName=%s\n", strerror(err), entryName.c_str());
count = err;
@@ -1374,7 +1376,7 @@
// containing no entries.
continue;
}
- if (file->getPath().getPathExtension() == ".xml") {
+ if (getPathExtension(file->getPath()) == ".xml") {
// We can't remove .xml files at this point, because when
// we parse them they may add identifier resources, so
// removing them can cause our resource identifiers to
@@ -1411,7 +1413,7 @@
// containing no entries.
continue;
}
- if (file->getPath().getPathExtension() == ".xml") {
+ if (getPathExtension(file->getPath()) == ".xml") {
// We can't remove .xml files at this point, because when
// we parse them they may add identifier resources, so
// removing them can cause our resource identifiers to
diff --git a/tools/aapt/Android.bp b/tools/aapt/Android.bp
index cecd95a..68db56d 100644
--- a/tools/aapt/Android.bp
+++ b/tools/aapt/Android.bp
@@ -51,6 +51,10 @@
"libz",
],
+ whole_static_libs: [
+ "libandroidfw_pathutils",
+ ],
+
cflags: [
"-Wall",
"-Werror",
diff --git a/tools/aapt/CacheUpdater.h b/tools/aapt/CacheUpdater.h
index 2dc143c..dc5493f 100644
--- a/tools/aapt/CacheUpdater.h
+++ b/tools/aapt/CacheUpdater.h
@@ -7,6 +7,7 @@
#ifndef CACHE_UPDATER_H
#define CACHE_UPDATER_H
+#include <androidfw/PathUtils.h>
#include <utils/String8.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -16,6 +17,8 @@
#include <direct.h>
#endif
+#include "Utils.h"
+
using namespace android;
/** CacheUpdater
@@ -72,14 +75,14 @@
do {
// As we remove the end of existsPath add it to
// the string of paths to create.
- toCreate = existsPath.getPathLeaf().appendPath(toCreate);
- existsPath = existsPath.getPathDir();
+ toCreate = appendPathCopy(getPathLeaf(existsPath), toCreate);
+ existsPath = getPathDir(existsPath);
} while (stat(existsPath.c_str(),&s) == -1);
// Walk forwards and build directories as we go
do {
// Advance to the next segment of the path
- existsPath.appendPath(toCreate.walkPath(&remains));
+ appendPath(existsPath, walkPath(toCreate, &remains));
toCreate = remains;
#ifdef _WIN32
_mkdir(existsPath.c_str());
@@ -101,7 +104,7 @@
virtual void processImage(String8 source, String8 dest)
{
// Make sure we're trying to write to a directory that is extant
- ensureDirectoriesExist(dest.getPathDir());
+ ensureDirectoriesExist(getPathDir(dest));
preProcessImageToCache(bundle, source, dest);
};
diff --git a/tools/aapt/Command.cpp b/tools/aapt/Command.cpp
index 60f3f27..800466a 100644
--- a/tools/aapt/Command.cpp
+++ b/tools/aapt/Command.cpp
@@ -12,6 +12,7 @@
#include "ResourceTable.h"
#include "XMLNode.h"
+#include <androidfw/PathUtils.h>
#include <utils/Errors.h>
#include <utils/KeyedVector.h>
#include <utils/List.h>
@@ -2486,12 +2487,12 @@
for (int i = 1; i < bundle->getFileSpecCount(); i++) {
const char* fileName = bundle->getFileSpecEntry(i);
- if (strcasecmp(String8(fileName).getPathExtension().c_str(), ".gz") == 0) {
+ if (strcasecmp(getPathExtension(String8(fileName)).c_str(), ".gz") == 0) {
printf(" '%s'... (from gzip)\n", fileName);
- result = zip->addGzip(fileName, String8(fileName).getBasePath().c_str(), NULL);
+ result = zip->addGzip(fileName, getBasePath(String8(fileName)).c_str(), NULL);
} else {
if (bundle->getJunkPath()) {
- String8 storageName = String8(fileName).getPathLeaf();
+ String8 storageName = getPathLeaf(String8(fileName));
printf(" '%s' as '%s'...\n", fileName,
ResTable::normalizeForOutput(storageName.c_str()).c_str());
result = zip->add(fileName, storageName.c_str(),
@@ -2617,10 +2618,10 @@
return original;
}
- String8 ext(original.getPathExtension());
+ String8 ext(getPathExtension(original));
if (ext == String8(".apk")) {
return String8::format("%s_%s%s",
- original.getBasePath().c_str(),
+ getBasePath(original).c_str(),
split->getDirectorySafeName().c_str(),
ext.c_str());
}
@@ -2756,7 +2757,7 @@
// generate the dependency file in the R.java package subdirectory
// e.g. gen/com/foo/app/R.java.d
dependencyFile = String8(bundle->getRClassDir());
- dependencyFile.appendPath("R.java.d");
+ appendPath(dependencyFile, "R.java.d");
}
// Make sure we have a clean dependency file to start with
fp = fopen(dependencyFile, "w");
diff --git a/tools/aapt/CrunchCache.cpp b/tools/aapt/CrunchCache.cpp
index 1f2febe..e731ce0 100644
--- a/tools/aapt/CrunchCache.cpp
+++ b/tools/aapt/CrunchCache.cpp
@@ -5,6 +5,7 @@
// This file defines functions laid out and documented in
// CrunchCache.h
+#include <androidfw/PathUtils.h>
#include <utils/Compat.h>
#include <utils/Vector.h>
#include <utils/String8.h>
@@ -52,15 +53,15 @@
relativePath = String8(rPathPtr + offset);
if (forceOverwrite || needsUpdating(relativePath)) {
- cu->processImage(mSourcePath.appendPathCopy(relativePath),
- mDestPath.appendPathCopy(relativePath));
+ cu->processImage(appendPathCopy(mSourcePath, relativePath),
+ appendPathCopy(mDestPath, relativePath));
numFilesUpdated++;
// crunchFile(relativePath);
}
// Delete this file from the source files and (if it exists) from the
// dest files.
mSourceFiles.removeItemsAt(0);
- mDestFiles.removeItem(mDestPath.appendPathCopy(relativePath));
+ mDestFiles.removeItem(appendPathCopy(mDestPath, relativePath));
}
// Iterate through what's left of destFiles and delete leftovers
@@ -99,7 +100,7 @@
// Retrieve modification dates for this file entry under the source and
// cache directory trees. The vectors will return a modification date of 0
// if the file doesn't exist.
- time_t sourceDate = mSourceFiles.valueFor(mSourcePath.appendPathCopy(relativePath));
- time_t destDate = mDestFiles.valueFor(mDestPath.appendPathCopy(relativePath));
+ time_t sourceDate = mSourceFiles.valueFor(appendPathCopy(mSourcePath, relativePath));
+ time_t destDate = mDestFiles.valueFor(appendPathCopy(mDestPath, relativePath));
return sourceDate > destDate;
}
diff --git a/tools/aapt/DirectoryWalker.h b/tools/aapt/DirectoryWalker.h
index cea3a6e..7f60d4d 100644
--- a/tools/aapt/DirectoryWalker.h
+++ b/tools/aapt/DirectoryWalker.h
@@ -7,6 +7,7 @@
#ifndef DIRECTORYWALKER_H
#define DIRECTORYWALKER_H
+#include <androidfw/PathUtils.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/param.h>
@@ -77,7 +78,7 @@
mEntry = *entryPtr;
// Get stats
- String8 fullPath = mBasePath.appendPathCopy(mEntry.d_name);
+ String8 fullPath = appendPathCopy(mBasePath, mEntry.d_name);
stat(fullPath.c_str(),&mStats);
return &mEntry;
};
diff --git a/tools/aapt/FileFinder.cpp b/tools/aapt/FileFinder.cpp
index a5c19806..69a8fa9 100644
--- a/tools/aapt/FileFinder.cpp
+++ b/tools/aapt/FileFinder.cpp
@@ -5,6 +5,7 @@
// File Finder implementation.
// Implementation for the functions declared and documented in FileFinder.h
+#include <androidfw/PathUtils.h>
#include <utils/Vector.h>
#include <utils/String8.h>
#include <utils/KeyedVector.h>
@@ -57,7 +58,7 @@
if (entry->d_name[0] == '.') // Skip hidden files and directories
continue;
- String8 fullPath = basePath.appendPathCopy(entryName);
+ String8 fullPath = appendPathCopy(basePath, entryName);
// If this entry is a directory we'll recurse into it
if (isDirectory(fullPath.c_str()) ) {
DirectoryWalker* copy = dw->clone();
@@ -83,10 +84,10 @@
{
// Loop over the extensions, checking for a match
bool done = false;
- String8 ext(path.getPathExtension());
+ String8 ext(getPathExtension(path));
ext.toLower();
for (size_t i = 0; i < extensions.size() && !done; ++i) {
- String8 ext2 = extensions[i].getPathExtension();
+ String8 ext2 = getPathExtension(extensions[i]);
ext2.toLower();
// Compare the extensions. If a match is found, add to storage.
if (ext == ext2) {
diff --git a/tools/aapt/Images.cpp b/tools/aapt/Images.cpp
index c6c7e96..cd4de90 100644
--- a/tools/aapt/Images.cpp
+++ b/tools/aapt/Images.cpp
@@ -8,6 +8,7 @@
#include "Images.h"
+#include <androidfw/PathUtils.h>
#include <androidfw/ResourceTypes.h>
#include <utils/ByteOrder.h>
@@ -1357,7 +1358,7 @@
status_t preProcessImage(const Bundle* bundle, const sp<AaptAssets>& /* assets */,
const sp<AaptFile>& file, String8* /* outNewLeafName */)
{
- String8 ext(file->getPath().getPathExtension());
+ String8 ext(getPathExtension(file->getPath()));
// We currently only process PNG images.
if (strcmp(ext.c_str(), ".png") != 0) {
@@ -1518,7 +1519,7 @@
// Check to see if we're dealing with a 9-patch
// If we are, process appropriately
- if (source.getBasePath().getPathExtension() == ".9") {
+ if (getPathExtension(getBasePath(source)) == ".9") {
if (do_9patch(source.c_str(), &imageInfo) != NO_ERROR) {
return error;
}
@@ -1584,12 +1585,12 @@
status_t postProcessImage(const Bundle* bundle, const sp<AaptAssets>& assets,
ResourceTable* table, const sp<AaptFile>& file)
{
- String8 ext(file->getPath().getPathExtension());
+ String8 ext(getPathExtension(file->getPath()));
// At this point, now that we have all the resource data, all we need to
// do is compile XML files.
if (strcmp(ext.c_str(), ".xml") == 0) {
- String16 resourceName(parseResourceName(file->getSourceFile().getPathLeaf()));
+ String16 resourceName(parseResourceName(getPathLeaf(file->getSourceFile())));
return compileXmlFile(bundle, assets, resourceName, file, table);
}
diff --git a/tools/aapt/Package.cpp b/tools/aapt/Package.cpp
index a7ff5fa..5e0f87f 100644
--- a/tools/aapt/Package.cpp
+++ b/tools/aapt/Package.cpp
@@ -10,6 +10,7 @@
#include "ResourceFilter.h"
#include "Utils.h"
+#include <androidfw/PathUtils.h>
#include <androidfw/misc.h>
#include <utils/Log.h>
@@ -170,7 +171,7 @@
/* anything here? */
if (zip->getNumEntries() == 0) {
if (bundle->getVerbose()) {
- printf("Archive is empty -- removing %s\n", outputFile.getPathLeaf().c_str());
+ printf("Archive is empty -- removing %s\n", getPathLeaf(outputFile).c_str());
}
delete zip; // close the file so we can remove it in Win32
zip = NULL;
@@ -274,9 +275,9 @@
return true;
}
- if (strcasecmp(storageName.getPathExtension().c_str(), ".gz") == 0) {
+ if (strcasecmp(getPathExtension(storageName).c_str(), ".gz") == 0) {
fromGzip = true;
- storageName = storageName.getBasePath();
+ storageName = getBasePath(storageName);
}
if (bundle->getUpdate()) {
@@ -366,7 +367,7 @@
*/
bool okayToCompress(Bundle* bundle, const String8& pathName)
{
- String8 ext = pathName.getPathExtension();
+ String8 ext = getPathExtension(pathName);
int i;
if (ext.length() == 0)
diff --git a/tools/aapt/Resource.cpp b/tools/aapt/Resource.cpp
index 4a360ed..3a198fd 100644
--- a/tools/aapt/Resource.cpp
+++ b/tools/aapt/Resource.cpp
@@ -19,6 +19,8 @@
#include "WorkQueue.h"
#include "XMLNode.h"
+#include <androidfw/PathUtils.h>
+
#include <algorithm>
// STATUST: mingw does seem to redefine UNKNOWN_ERROR from our enum value, so a cast is necessary.
@@ -143,8 +145,8 @@
mParams.inputFlags, mParams.navigation);
}
mPath = "res";
- mPath.appendPath(file->getGroupEntry().toDirName(mResType));
- mPath.appendPath(leaf);
+ appendPath(mPath, file->getGroupEntry().toDirName(mResType));
+ appendPath(mPath, leaf);
mBaseName = parseResourceName(leaf);
if (mBaseName == "") {
fprintf(stderr, "Error: malformed resource filename %s\n",
@@ -779,7 +781,7 @@
if (kIsDebug) {
printf("Qualifying class '%s' to '%s'", name.c_str(), className.c_str());
}
- attr->string.setTo(String16(className));
+ attr->string = String16(className);
}
}
@@ -969,7 +971,7 @@
return UNKNOWN_ERROR;
}
String8 origPackage(attr->string);
- attr->string.setTo(String16(manifestPackageNameOverride));
+ attr->string = String16(manifestPackageNameOverride);
if (kIsDebug) {
printf("Overriding package '%s' to be '%s'\n", origPackage.c_str(),
manifestPackageNameOverride);
@@ -1007,7 +1009,7 @@
XMLNode::attribute_entry* attr = child->editAttribute(
String16(RESOURCES_ANDROID_NAMESPACE), String16("targetPackage"));
if (attr != NULL) {
- attr->string.setTo(String16(instrumentationPackageNameOverride));
+ attr->string = String16(instrumentationPackageNameOverride);
}
}
}
@@ -1686,7 +1688,7 @@
ResourceDirIterator it(fonts, String8("font"));
while ((err=it.next()) == NO_ERROR) {
// fonts can be resources other than xml.
- if (it.getFile()->getPath().getPathExtension() == ".xml") {
+ if (getPathExtension(it.getFile()->getPath()) == ".xml") {
String8 src = it.getFile()->getPrintableSource();
err = compileXmlFile(bundle, assets, String16(it.getBaseName()),
it.getFile(), &table, xmlFlags);
@@ -1716,7 +1718,7 @@
workItem.file, &table, xmlCompilationFlags);
if (err == NO_ERROR && workItem.file->hasData()) {
- assets->addResource(workItem.resPath.getPathLeaf(),
+ assets->addResource(getPathLeaf(workItem.resPath),
workItem.resPath,
workItem.file,
workItem.file->getResourceType());
@@ -2851,7 +2853,7 @@
s++;
if (s > last && (*s == '.' || *s == 0)) {
String8 part(last, s-last);
- dest.appendPath(part);
+ appendPath(dest, part);
#ifdef _WIN32
_mkdir(dest.c_str());
#else
@@ -2861,7 +2863,7 @@
}
} while (*s);
}
- dest.appendPath(className);
+ appendPath(dest, className);
dest.append(".java");
FILE* fp = fopen(dest.c_str(), "w+");
if (fp == NULL) {
@@ -2892,7 +2894,7 @@
if (textSymbolsDest != NULL && R == className) {
String8 textDest(textSymbolsDest);
- textDest.appendPath(className);
+ appendPath(textDest, className);
textDest.append(".txt");
FILE* fp = fopen(textDest.c_str(), "w+");
@@ -2918,7 +2920,7 @@
if (bundle->getGenDependencies() && R == className) {
// Add this R.java to the dependency file
String8 dependencyFile(bundle->getRClassDir());
- dependencyFile.appendPath("R.java.d");
+ appendPath(dependencyFile, "R.java.d");
FILE *fp = fopen(dependencyFile.c_str(), "a");
fprintf(fp,"%s \\\n", dest.c_str());
diff --git a/tools/aapt/ResourceTable.cpp b/tools/aapt/ResourceTable.cpp
index bccf73e..620e272 100644
--- a/tools/aapt/ResourceTable.cpp
+++ b/tools/aapt/ResourceTable.cpp
@@ -14,6 +14,7 @@
#include "Utils.h"
#include <algorithm>
+#include <androidfw/PathUtils.h>
#include <androidfw/ResourceTypes.h>
#include <utils/ByteOrder.h>
#include <utils/TypeHelpers.h>
@@ -83,7 +84,7 @@
sp<AaptDir> resDir = assets->getDirs().valueFor(String8("res"));
sp<AaptDir> dir = resDir->getDirs().valueFor(target->getGroupEntry().toDirName(
target->getResourceType()));
- dir->removeFile(target->getPath().getPathLeaf());
+ dir->removeFile(getPathLeaf(target->getPath()));
return NO_ERROR;
}
@@ -1363,11 +1364,11 @@
size_t length;
const char16_t* attr = block.getAttributeName(i, &length);
if (strcmp16(attr, name16.c_str()) == 0) {
- name.setTo(block.getAttributeStringValue(i, &length));
+ name = String16(block.getAttributeStringValue(i, &length));
} else if (strcmp16(attr, translatable16.c_str()) == 0) {
- translatable.setTo(block.getAttributeStringValue(i, &length));
+ translatable = String16(block.getAttributeStringValue(i, &length));
} else if (strcmp16(attr, formatted16.c_str()) == 0) {
- formatted.setTo(block.getAttributeStringValue(i, &length));
+ formatted = String16(block.getAttributeStringValue(i, &length));
}
}
@@ -1541,7 +1542,7 @@
} else {
ssize_t sep = ident.findLast('.');
if (sep >= 0) {
- parentIdent.setTo(ident, sep);
+ parentIdent = String16(ident, sep);
}
}
@@ -2831,10 +2832,10 @@
String8 config;
comma = strchr(start, ',');
if (comma != NULL) {
- config.setTo(start, comma - start);
+ config = String8(start, comma - start);
start = comma + 1;
} else {
- config.setTo(start);
+ config = start;
}
if (!locale.initFromFilterString(config)) {
diff --git a/tools/aapt/Utils.cpp b/tools/aapt/Utils.cpp
index 36b018e..946916a 100644
--- a/tools/aapt/Utils.cpp
+++ b/tools/aapt/Utils.cpp
@@ -36,3 +36,26 @@
}
#endif
}
+
+String8 walkPath(const String8& path, String8* outRemains) {
+ const char* cp;
+ const char* const str = path.c_str();
+ const char* buf = str;
+
+ cp = strchr(buf, OS_PATH_SEPARATOR);
+ if (cp == buf) {
+ // don't include a leading '/'.
+ buf = buf + 1;
+ cp = strchr(buf, OS_PATH_SEPARATOR);
+ }
+
+ if (cp == nullptr) {
+ String8 res = buf != str ? String8(buf) : path;
+ if (outRemains) *outRemains = String8();
+ return res;
+ }
+
+ String8 res(buf, cp - buf);
+ if (outRemains) *outRemains = String8(cp + 1);
+ return res;
+}
diff --git a/tools/aapt/Utils.h b/tools/aapt/Utils.h
index 8eb5941..f0d6979 100644
--- a/tools/aapt/Utils.h
+++ b/tools/aapt/Utils.h
@@ -26,3 +26,13 @@
// If the default OS separator is backslash, this converts all
// backslashes to slashes, in-place. Otherwise it does nothing.
void convertToResPath(android::String8&);
+
+/**
+ * Retrieve the front (root dir) component. Optionally also return the
+ * remaining components.
+ *
+ * "/tmp/foo/bar.c" --> "tmp" (remain = "foo/bar.c")
+ * "/tmp" --> "tmp" (remain = "")
+ * "bar.c" --> "bar.c" (remain = "")
+ */
+android::String8 walkPath(const android::String8& path, android::String8* outRemains = nullptr);
diff --git a/tools/aapt/XMLNode.cpp b/tools/aapt/XMLNode.cpp
index e270a73..a887ac9 100644
--- a/tools/aapt/XMLNode.cpp
+++ b/tools/aapt/XMLNode.cpp
@@ -334,9 +334,9 @@
String16 spanTag;
ssize_t semi = span.name.findFirst(';');
if (semi >= 0) {
- spanTag.setTo(span.name.c_str(), semi);
+ spanTag = String16(span.name.c_str(), semi);
} else {
- spanTag.setTo(span.name);
+ spanTag = span.name;
}
if (strcmp16(inXml->getElementName(&len), spanTag.c_str()) != 0) {
SourcePos(String8(fileName), inXml->getLineNumber()).error(
@@ -393,7 +393,7 @@
// later as part of the overall type conversion. Return to the
// client the raw unprocessed text.
rawString.append(curString);
- outString->setTo(rawString);
+ *outString = rawString;
}
return NO_ERROR;
diff --git a/tools/aapt2/dump/DumpManifest.cpp b/tools/aapt2/dump/DumpManifest.cpp
index 9828b97..f93949b 100644
--- a/tools/aapt2/dump/DumpManifest.cpp
+++ b/tools/aapt2/dump/DumpManifest.cpp
@@ -116,9 +116,7 @@
class ManifestExtractor {
public:
-
- explicit ManifestExtractor(LoadedApk* apk, DumpManifestOptions& options)
- : apk_(apk), options_(options) { }
+ explicit ManifestExtractor(LoadedApk* apk, DumpManifestOptions& options);
class Element {
public:
@@ -387,7 +385,7 @@
DumpManifestOptions& options_;
private:
- std::unique_ptr<CommonFeatureGroup> commonFeatureGroup_ = util::make_unique<CommonFeatureGroup>();
+ std::unique_ptr<CommonFeatureGroup> commonFeatureGroup_;
std::map<std::string, ConfigDescription> locales_;
std::map<uint16_t, ConfigDescription> densities_;
std::vector<Element*> parent_stack_;
@@ -1970,6 +1968,12 @@
}
}
+// Define this constructor after the CommonFeatureGroup class definition to avoid errors with using
+// std::unique_ptr on an incomplete type.
+ManifestExtractor::ManifestExtractor(LoadedApk* apk, DumpManifestOptions& options)
+ : apk_(apk), options_(options), commonFeatureGroup_(util::make_unique<CommonFeatureGroup>()) {
+}
+
bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) {
// Load the manifest
std::unique_ptr<xml::XmlResource> doc = apk_->LoadXml("AndroidManifest.xml", diag);
diff --git a/tools/lint/common/Android.bp b/tools/lint/common/Android.bp
index 898f88b..8bfbfe5 100644
--- a/tools/lint/common/Android.bp
+++ b/tools/lint/common/Android.bp
@@ -27,3 +27,30 @@
libs: ["lint_api"],
kotlincflags: ["-Xjvm-default=all"],
}
+
+java_defaults {
+ name: "AndroidLintCheckerTestDefaults",
+ srcs: ["checks/src/test/java/**/*.kt"],
+ static_libs: [
+ "junit",
+ "lint",
+ "lint_tests",
+ ],
+ test_options: {
+ unit_test: true,
+ tradefed_options: [
+ {
+ // lint bundles in some classes that were built with older versions
+ // of libraries, and no longer load. Since tradefed tries to load
+ // all classes in the jar to look for tests, it crashes loading them.
+ // Exclude these classes from tradefed's search.
+ name: "exclude-paths",
+ value: "org/apache",
+ },
+ {
+ name: "exclude-paths",
+ value: "META-INF",
+ },
+ ],
+ },
+}
diff --git a/tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/AidlImplementationDetector.kt b/tools/lint/common/src/main/java/com/google/android/lint/aidl/AidlImplementationDetector.kt
similarity index 100%
rename from tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/AidlImplementationDetector.kt
rename to tools/lint/common/src/main/java/com/google/android/lint/aidl/AidlImplementationDetector.kt
diff --git a/tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/Constants.kt b/tools/lint/common/src/main/java/com/google/android/lint/aidl/Constants.kt
similarity index 100%
rename from tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/Constants.kt
rename to tools/lint/common/src/main/java/com/google/android/lint/aidl/Constants.kt
diff --git a/tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/EnforcePermissionUtils.kt b/tools/lint/common/src/main/java/com/google/android/lint/aidl/EnforcePermissionUtils.kt
similarity index 100%
rename from tools/lint/global/checks/src/main/java/com/google/android/lint/aidl/EnforcePermissionUtils.kt
rename to tools/lint/common/src/main/java/com/google/android/lint/aidl/EnforcePermissionUtils.kt
diff --git a/tools/lint/fix/soong_lint_fix.py b/tools/lint/fix/soong_lint_fix.py
index cd4d778d..acc0ad0 100644
--- a/tools/lint/fix/soong_lint_fix.py
+++ b/tools/lint/fix/soong_lint_fix.py
@@ -29,6 +29,39 @@
PATH_SUFFIX = "android_common/lint"
FIX_ZIP = "suggested-fixes.zip"
+
+class SoongModule:
+ """A Soong module to lint.
+
+ The constructor takes the name of the module (for example,
+ "framework-minus-apex"). find() must be called to extract the intermediate
+ module path from Soong's module-info.json
+ """
+ def __init__(self, name):
+ self._name = name
+
+ def find(self, module_info):
+ """Finds the module in the loaded module_info.json."""
+ if self._name not in module_info:
+ raise Exception(f"Module {self._name} not found!")
+
+ partial_path = module_info[self._name]["path"][0]
+ print(f"Found module {partial_path}/{self._name}.")
+ self._path = f"{PATH_PREFIX}/{partial_path}/{self._name}/{PATH_SUFFIX}"
+
+ @property
+ def name(self):
+ return self._name
+
+ @property
+ def lint_report(self):
+ return f"{self._path}/lint-report.txt"
+
+ @property
+ def suggested_fixes(self):
+ return f"{self._path}/{FIX_ZIP}"
+
+
class SoongLintFix:
"""
This class creates a command line tool that will
@@ -53,16 +86,14 @@
self._parser = _setup_parser()
self._args = None
self._kwargs = None
- self._path = None
- self._target = None
+ self._modules = []
-
- def run(self, additional_setup=None, custom_fix=None):
+ def run(self):
"""
Run the script
"""
self._setup()
- self._find_module()
+ self._find_modules()
self._lint()
if not self._args.no_fix:
@@ -87,8 +118,6 @@
os.chdir(ANDROID_BUILD_TOP)
-
- def _find_module(self):
print("Refreshing soong modules...")
try:
os.mkdir(ANDROID_PRODUCT_OUT)
@@ -97,48 +126,47 @@
subprocess.call(f"{SOONG_UI} --make-mode {PRODUCT_OUT}/module-info.json", **self._kwargs)
print("done.")
+
+ def _find_modules(self):
with open(f"{ANDROID_PRODUCT_OUT}/module-info.json") as f:
module_info = json.load(f)
- if self._args.module not in module_info:
- sys.exit(f"Module {self._args.module} not found!")
-
- module_path = module_info[self._args.module]["path"][0]
- print(f"Found module {module_path}/{self._args.module}.")
-
- self._path = f"{PATH_PREFIX}/{module_path}/{self._args.module}/{PATH_SUFFIX}"
- self._target = f"{self._path}/lint-report.txt"
-
+ for module_name in self._args.modules:
+ module = SoongModule(module_name)
+ module.find(module_info)
+ self._modules.append(module)
def _lint(self):
print("Cleaning up any old lint results...")
- try:
- os.remove(f"{self._target}")
- os.remove(f"{self._path}/{FIX_ZIP}")
- except FileNotFoundError:
- pass
+ for module in self._modules:
+ try:
+ os.remove(f"{module.lint_report}")
+ os.remove(f"{module.suggested_fixes}")
+ except FileNotFoundError:
+ pass
print("done.")
- print(f"Generating {self._target}")
- subprocess.call(f"{SOONG_UI} --make-mode {self._target}", **self._kwargs)
+ target = " ".join([ module.lint_report for module in self._modules ])
+ print(f"Generating {target}")
+ subprocess.call(f"{SOONG_UI} --make-mode {target}", **self._kwargs)
print("done.")
-
def _fix(self):
- print("Copying suggested fixes to the tree...")
- with zipfile.ZipFile(f"{self._path}/{FIX_ZIP}") as zip:
- for name in zip.namelist():
- if name.startswith("out") or not name.endswith(".java"):
- continue
- with zip.open(name) as src, open(f"{ANDROID_BUILD_TOP}/{name}", "wb") as dst:
- shutil.copyfileobj(src, dst)
+ for module in self._modules:
+ print(f"Copying suggested fixes for {module.name} to the tree...")
+ with zipfile.ZipFile(f"{module.suggested_fixes}") as zip:
+ for name in zip.namelist():
+ if name.startswith("out") or not name.endswith(".java"):
+ continue
+ with zip.open(name) as src, open(f"{ANDROID_BUILD_TOP}/{name}", "wb") as dst:
+ shutil.copyfileobj(src, dst)
print("done.")
-
def _print(self):
- print("### lint-report.txt ###", end="\n\n")
- with open(self._target, "r") as f:
- print(f.read())
+ for module in self._modules:
+ print(f"### lint-report.txt {module.name} ###", end="\n\n")
+ with open(module.lint_report, "r") as f:
+ print(f.read())
def _setup_parser():
@@ -151,7 +179,8 @@
**Gotcha**: You must have run `source build/envsetup.sh` and `lunch` first.
""", formatter_class=argparse.RawTextHelpFormatter)
- parser.add_argument('module',
+ parser.add_argument('modules',
+ nargs='+',
help='The soong build module to run '
'(e.g. framework-minus-apex or services.core.unboosted)')
@@ -170,4 +199,4 @@
return parser
if __name__ == "__main__":
- SoongLintFix().run()
\ No newline at end of file
+ SoongLintFix().run()
diff --git a/tools/lint/framework/Android.bp b/tools/lint/framework/Android.bp
index 30a6daa..5acdf43 100644
--- a/tools/lint/framework/Android.bp
+++ b/tools/lint/framework/Android.bp
@@ -37,28 +37,9 @@
java_test_host {
name: "AndroidFrameworkLintCheckerTest",
+ defaults: ["AndroidLintCheckerTestDefaults"],
srcs: ["checks/src/test/java/**/*.kt"],
static_libs: [
"AndroidFrameworkLintChecker",
- "junit",
- "lint",
- "lint_tests",
],
- test_options: {
- unit_test: true,
- tradefed_options: [
- {
- // lint bundles in some classes that were built with older versions
- // of libraries, and no longer load. Since tradefed tries to load
- // all classes in the jar to look for tests, it crashes loading them.
- // Exclude these classes from tradefed's search.
- name: "exclude-paths",
- value: "org/apache",
- },
- {
- name: "exclude-paths",
- value: "META-INF",
- },
- ],
- },
}
diff --git a/tools/lint/global/Android.bp b/tools/lint/global/Android.bp
index bedb7bd..3e74171 100644
--- a/tools/lint/global/Android.bp
+++ b/tools/lint/global/Android.bp
@@ -38,28 +38,9 @@
java_test_host {
name: "AndroidGlobalLintCheckerTest",
+ defaults: ["AndroidLintCheckerTestDefaults"],
srcs: ["checks/src/test/java/**/*.kt"],
static_libs: [
"AndroidGlobalLintChecker",
- "junit",
- "lint",
- "lint_tests",
],
- test_options: {
- unit_test: true,
- tradefed_options: [
- {
- // lint bundles in some classes that were built with older versions
- // of libraries, and no longer load. Since tradefed tries to load
- // all classes in the jar to look for tests, it crashes loading them.
- // Exclude these classes from tradefed's search.
- name: "exclude-paths",
- value: "org/apache",
- },
- {
- name: "exclude-paths",
- value: "META-INF",
- },
- ],
- },
}
diff --git a/tools/lint/utils/Android.bp b/tools/lint/utils/Android.bp
new file mode 100644
index 0000000..75e8d68
--- /dev/null
+++ b/tools/lint/utils/Android.bp
@@ -0,0 +1,45 @@
+// Copyright (C) 2023 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 {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "frameworks_base_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ default_applicable_licenses: ["frameworks_base_license"],
+}
+
+java_library_host {
+ name: "AndroidUtilsLintChecker",
+ srcs: ["checks/src/main/java/**/*.kt"],
+ plugins: ["auto_service_plugin"],
+ libs: [
+ "auto_service_annotations",
+ "lint_api",
+ ],
+ static_libs: [
+ "AndroidCommonLint",
+ ],
+ kotlincflags: ["-Xjvm-default=all"],
+}
+
+java_test_host {
+ name: "AndroidUtilsLintCheckerTest",
+ defaults: ["AndroidLintCheckerTestDefaults"],
+ srcs: ["checks/src/test/java/**/*.kt"],
+ static_libs: [
+ "AndroidUtilsLintChecker",
+ ],
+}
diff --git a/tools/lint/utils/checks/src/main/java/com/google/android/lint/AndroidUtilsIssueRegistry.kt b/tools/lint/utils/checks/src/main/java/com/google/android/lint/AndroidUtilsIssueRegistry.kt
new file mode 100644
index 0000000..fa61c42
--- /dev/null
+++ b/tools/lint/utils/checks/src/main/java/com/google/android/lint/AndroidUtilsIssueRegistry.kt
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2023 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.google.android.lint
+
+import com.android.tools.lint.client.api.IssueRegistry
+import com.android.tools.lint.client.api.Vendor
+import com.android.tools.lint.detector.api.CURRENT_API
+import com.google.android.lint.aidl.AnnotatedAidlCounter
+import com.google.auto.service.AutoService
+
+@AutoService(IssueRegistry::class)
+@Suppress("UnstableApiUsage")
+class AndroidUtilsIssueRegistry : IssueRegistry() {
+ override val issues = listOf(
+ AnnotatedAidlCounter.ISSUE_ANNOTATED_AIDL_COUNTER,
+ )
+
+ override val api: Int
+ get() = CURRENT_API
+
+ override val minApi: Int
+ get() = 8
+
+ override val vendor: Vendor = Vendor(
+ vendorName = "Android",
+ feedbackUrl = "http://b/issues/new?component=315013",
+ contact = "tweek@google.com"
+ )
+}
diff --git a/tools/lint/utils/checks/src/main/java/com/google/android/lint/aidl/AnnotatedAidlCounter.kt b/tools/lint/utils/checks/src/main/java/com/google/android/lint/aidl/AnnotatedAidlCounter.kt
new file mode 100644
index 0000000..f0ec3f4
--- /dev/null
+++ b/tools/lint/utils/checks/src/main/java/com/google/android/lint/aidl/AnnotatedAidlCounter.kt
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2023 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.google.android.lint.aidl
+
+import com.android.tools.lint.detector.api.Category
+import com.android.tools.lint.detector.api.Context
+import com.android.tools.lint.detector.api.Implementation
+import com.android.tools.lint.detector.api.Issue
+import com.android.tools.lint.detector.api.JavaContext
+import com.android.tools.lint.detector.api.Location
+import com.android.tools.lint.detector.api.Scope
+import com.android.tools.lint.detector.api.Severity
+import org.jetbrains.uast.UBlockExpression
+import org.jetbrains.uast.UMethod
+
+import java.util.TreeMap
+
+/**
+ * Count the number of AIDL interfaces. Reports the number of annotated and
+ * non-annotated methods.
+ */
+@Suppress("UnstableApiUsage")
+class AnnotatedAidlCounter : AidlImplementationDetector() {
+
+ private data class Stat(
+ var unannotated: Int = 0,
+ var enforced: Int = 0,
+ var notRequired: Int = 0,
+ )
+
+ private var packagesStats: TreeMap<String, Stat> = TreeMap<String, Stat>()
+
+ override fun visitAidlMethod(
+ context: JavaContext,
+ node: UMethod,
+ interfaceName: String,
+ body: UBlockExpression
+ ) {
+ val packageName = context.uastFile?.packageName ?: "<unknown>"
+ var packageStat = packagesStats.getOrDefault(packageName, Stat())
+ when {
+ node.hasAnnotation(ANNOTATION_ENFORCE_PERMISSION) -> packageStat.enforced += 1
+ node.hasAnnotation(ANNOTATION_REQUIRES_NO_PERMISSION) -> packageStat.notRequired += 1
+ else -> packageStat.unannotated += 1
+ }
+ packagesStats.put(packageName, packageStat)
+ // context.driver.client.log(null, "%s.%s#%s".format(packageName, interfaceName, node.name))
+ }
+
+ override fun afterCheckRootProject(context: Context) {
+ var total = Stat()
+ for ((packageName, stat) in packagesStats) {
+ context.client.log(null, "package $packageName => $stat")
+ total.unannotated += stat.unannotated
+ total.enforced += stat.enforced
+ total.notRequired += stat.notRequired
+ }
+ val location = Location.create(context.project.dir)
+ context.report(
+ ISSUE_ANNOTATED_AIDL_COUNTER,
+ location,
+ "module ${context.project.name} => $total"
+ )
+ }
+
+ companion object {
+
+ @JvmField
+ val ISSUE_ANNOTATED_AIDL_COUNTER = Issue.create(
+ id = "AnnotatedAidlCounter",
+ briefDescription = "Statistics on the number of annotated AIDL methods.",
+ explanation = "",
+ category = Category.SECURITY,
+ priority = 5,
+ severity = Severity.INFORMATIONAL,
+ implementation = Implementation(
+ AnnotatedAidlCounter::class.java,
+ Scope.JAVA_FILE_SCOPE
+ ),
+ )
+ }
+}
diff --git a/tools/lint/utils/checks/src/test/java/com/google/android/lint/aidl/AnnotatedAidlCounterTest.kt b/tools/lint/utils/checks/src/test/java/com/google/android/lint/aidl/AnnotatedAidlCounterTest.kt
new file mode 100644
index 0000000..692b7da
--- /dev/null
+++ b/tools/lint/utils/checks/src/test/java/com/google/android/lint/aidl/AnnotatedAidlCounterTest.kt
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2023 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.google.android.lint.aidl
+
+import com.android.tools.lint.checks.infrastructure.LintDetectorTest
+import com.android.tools.lint.checks.infrastructure.TestFile
+import com.android.tools.lint.checks.infrastructure.TestLintTask
+import com.android.tools.lint.detector.api.Detector
+import com.android.tools.lint.detector.api.Issue
+
+@Suppress("UnstableApiUsage")
+class AnnotatedAidlCounterTest : LintDetectorTest() {
+ override fun getDetector(): Detector = AnnotatedAidlCounter()
+
+ override fun getIssues(): List<Issue> = listOf(
+ AnnotatedAidlCounter.ISSUE_ANNOTATED_AIDL_COUNTER,
+ )
+
+ override fun lint(): TestLintTask = super.lint().allowMissingSdk(true)
+
+ /** No issue scenario */
+
+ fun testDoesNotDetectIssuesCorrectAnnotationOnMethod() {
+ lint().files(java(
+ """
+ package test.pkg;
+ import android.annotation.EnforcePermission;
+ public class TestClass2 extends IFooMethod.Stub {
+ @Override
+ @EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
+ public void testMethod() {}
+ }
+ """).indented(),
+ *stubs
+ )
+ .run()
+ .expect("""
+ app: Information: module app => Stat(unannotated=0, enforced=1, notRequired=0) [AnnotatedAidlCounter]
+ 0 errors, 0 warnings
+ """)
+ }
+
+ // A service with permission annotation on the method.
+ private val interfaceIFooMethodStub: TestFile = java(
+ """
+ public interface IFooMethod extends android.os.IInterface {
+ public static abstract class Stub extends android.os.Binder implements IFooMethod {}
+ @android.annotation.EnforcePermission(android.Manifest.permission.READ_PHONE_STATE)
+ public void testMethod();
+ }
+ """
+ ).indented()
+
+ // A service without any permission annotation.
+ private val interfaceIBarStub: TestFile = java(
+ """
+ public interface IBar extends android.os.IInterface {
+ public static abstract class Stub extends android.os.Binder implements IBar {
+ @Override
+ public void testMethod() {}
+ }
+ public void testMethod();
+ }
+ """
+ ).indented()
+
+ private val manifestPermissionStub: TestFile = java(
+ """
+ package android.Manifest;
+ class permission {
+ public static final String READ_PHONE_STATE = "android.permission.READ_PHONE_STATE";
+ }
+ """
+ ).indented()
+
+ private val enforcePermissionAnnotationStub: TestFile = java(
+ """
+ package android.annotation;
+ public @interface EnforcePermission {}
+ """
+ ).indented()
+
+ private val stubs = arrayOf(interfaceIFooMethodStub, interfaceIBarStub,
+ manifestPermissionStub, enforcePermissionAnnotationStub)
+}
diff --git a/tools/split-select/Main.cpp b/tools/split-select/Main.cpp
index 1e75117..73bfa19 100644
--- a/tools/split-select/Main.cpp
+++ b/tools/split-select/Main.cpp
@@ -257,7 +257,7 @@
usage();
return 1;
}
- targetConfigStr.setTo(*argv);
+ targetConfigStr = *argv;
} else if (arg == "--split") {
argc--;
argv++;
@@ -281,7 +281,7 @@
usage();
return 1;
}
- baseApkPath.setTo(*argv);
+ baseApkPath = *argv;
} else if (arg == "--generate") {
generateFlag = true;
} else if (arg == "--help") {
diff --git a/tools/split-select/SplitDescription.cpp b/tools/split-select/SplitDescription.cpp
index 7150008..c02e2d7 100644
--- a/tools/split-select/SplitDescription.cpp
+++ b/tools/split-select/SplitDescription.cpp
@@ -134,10 +134,10 @@
String8 configStr;
String8 extensionStr;
if (index >= 0) {
- configStr.setTo(str.c_str(), index);
- extensionStr.setTo(str.c_str() + index + 1);
+ configStr = String8(str.c_str(), index);
+ extensionStr = (str.c_str() + index + 1);
} else {
- configStr.setTo(str);
+ configStr = str;
}
SplitDescription split;