Merge "Revert "Remove unused codes that was used in setChildChain""
This commit is contained in:
@@ -82,6 +82,13 @@ static jint native_removeNiceApp(JNIEnv* env, jobject self, jint uid) {
|
|||||||
return (jint)status.code();
|
return (jint)status.code();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static jint native_setChildChain(JNIEnv* env, jobject self, jint childChain, jboolean enable) {
|
||||||
|
auto chain = static_cast<ChildChain>(childChain);
|
||||||
|
int res = mTc.toggleUidOwnerMap(chain, enable);
|
||||||
|
if (res) ALOGE("%s failed, error code = %d", __func__, res);
|
||||||
|
return (jint)res;
|
||||||
|
}
|
||||||
|
|
||||||
static jint native_replaceUidChain(JNIEnv* env, jobject self, jstring name, jboolean isAllowlist,
|
static jint native_replaceUidChain(JNIEnv* env, jobject self, jstring name, jboolean isAllowlist,
|
||||||
jintArray jUids) {
|
jintArray jUids) {
|
||||||
const ScopedUtfChars chainNameUtf8(env, name);
|
const ScopedUtfChars chainNameUtf8(env, name);
|
||||||
@@ -192,6 +199,8 @@ static const JNINativeMethod gMethods[] = {
|
|||||||
(void*)native_addNiceApp},
|
(void*)native_addNiceApp},
|
||||||
{"native_removeNiceApp", "(I)I",
|
{"native_removeNiceApp", "(I)I",
|
||||||
(void*)native_removeNiceApp},
|
(void*)native_removeNiceApp},
|
||||||
|
{"native_setChildChain", "(IZ)I",
|
||||||
|
(void*)native_setChildChain},
|
||||||
{"native_replaceUidChain", "(Ljava/lang/String;Z[I)I",
|
{"native_replaceUidChain", "(Ljava/lang/String;Z[I)I",
|
||||||
(void*)native_replaceUidChain},
|
(void*)native_replaceUidChain},
|
||||||
{"native_setUidRule", "(III)I",
|
{"native_setUidRule", "(III)I",
|
||||||
|
|||||||
@@ -451,6 +451,53 @@ int TrafficController::replaceUidOwnerMap(const std::string& name, bool isAllowl
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TrafficController::toggleUidOwnerMap(ChildChain chain, bool enable) {
|
||||||
|
std::lock_guard guard(mMutex);
|
||||||
|
uint32_t key = UID_RULES_CONFIGURATION_KEY;
|
||||||
|
auto oldConfigure = mConfigurationMap.readValue(key);
|
||||||
|
if (!oldConfigure.ok()) {
|
||||||
|
ALOGE("Cannot read the old configuration from map: %s",
|
||||||
|
oldConfigure.error().message().c_str());
|
||||||
|
return -oldConfigure.error().code();
|
||||||
|
}
|
||||||
|
uint32_t match;
|
||||||
|
switch (chain) {
|
||||||
|
case DOZABLE:
|
||||||
|
match = DOZABLE_MATCH;
|
||||||
|
break;
|
||||||
|
case STANDBY:
|
||||||
|
match = STANDBY_MATCH;
|
||||||
|
break;
|
||||||
|
case POWERSAVE:
|
||||||
|
match = POWERSAVE_MATCH;
|
||||||
|
break;
|
||||||
|
case RESTRICTED:
|
||||||
|
match = RESTRICTED_MATCH;
|
||||||
|
break;
|
||||||
|
case LOW_POWER_STANDBY:
|
||||||
|
match = LOW_POWER_STANDBY_MATCH;
|
||||||
|
break;
|
||||||
|
case OEM_DENY_1:
|
||||||
|
match = OEM_DENY_1_MATCH;
|
||||||
|
break;
|
||||||
|
case OEM_DENY_2:
|
||||||
|
match = OEM_DENY_2_MATCH;
|
||||||
|
break;
|
||||||
|
case OEM_DENY_3:
|
||||||
|
match = OEM_DENY_3_MATCH;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
BpfConfig newConfiguration =
|
||||||
|
enable ? (oldConfigure.value() | match) : (oldConfigure.value() & ~match);
|
||||||
|
Status res = mConfigurationMap.writeValue(key, newConfiguration, BPF_EXIST);
|
||||||
|
if (!isOk(res)) {
|
||||||
|
ALOGE("Failed to toggleUidOwnerMap(%d): %s", chain, res.msg().c_str());
|
||||||
|
}
|
||||||
|
return -res.code();
|
||||||
|
}
|
||||||
|
|
||||||
Status TrafficController::swapActiveStatsMap() {
|
Status TrafficController::swapActiveStatsMap() {
|
||||||
std::lock_guard guard(mMutex);
|
std::lock_guard guard(mMutex);
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ class TrafficController {
|
|||||||
netdutils::Status updateUidOwnerMap(const uint32_t uid,
|
netdutils::Status updateUidOwnerMap(const uint32_t uid,
|
||||||
UidOwnerMatchType matchType, IptOp op) EXCLUDES(mMutex);
|
UidOwnerMatchType matchType, IptOp op) EXCLUDES(mMutex);
|
||||||
|
|
||||||
|
int toggleUidOwnerMap(ChildChain chain, bool enable) EXCLUDES(mMutex);
|
||||||
|
|
||||||
static netdutils::StatusOr<std::unique_ptr<netdutils::NetlinkListenerInterface>>
|
static netdutils::StatusOr<std::unique_ptr<netdutils::NetlinkListenerInterface>>
|
||||||
makeSkDestroyListener();
|
makeSkDestroyListener();
|
||||||
|
|
||||||
|
|||||||
@@ -637,6 +637,7 @@ public class BpfNetMaps {
|
|||||||
private native int native_addNiceApp(int uid);
|
private native int native_addNiceApp(int uid);
|
||||||
@GuardedBy("sUidOwnerMap")
|
@GuardedBy("sUidOwnerMap")
|
||||||
private native int native_removeNiceApp(int uid);
|
private native int native_removeNiceApp(int uid);
|
||||||
|
private native int native_setChildChain(int childChain, boolean enable);
|
||||||
@GuardedBy("sUidOwnerMap")
|
@GuardedBy("sUidOwnerMap")
|
||||||
private native int native_replaceUidChain(String name, boolean isAllowlist, int[] uids);
|
private native int native_replaceUidChain(String name, boolean isAllowlist, int[] uids);
|
||||||
@GuardedBy("sUidOwnerMap")
|
@GuardedBy("sUidOwnerMap")
|
||||||
|
|||||||
Reference in New Issue
Block a user