mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-17 11:38:51 +01:00
Remove unused classes
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates a constant field value should be exported to be used in the SDK tools.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface SdkConstant {
|
||||
public static enum SdkConstantType {
|
||||
ACTIVITY_INTENT_ACTION, BROADCAST_INTENT_ACTION, SERVICE_ACTION, INTENT_CATEGORY, FEATURE;
|
||||
}
|
||||
|
||||
SdkConstantType value();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,494 +0,0 @@
|
||||
/*
|
||||
* This file is auto-generated. DO NOT MODIFY.
|
||||
* Original file: frameworks/base/core/java/android/net/INetworkPolicyManager.aidl
|
||||
*/
|
||||
package android.net;
|
||||
|
||||
/**
|
||||
* Interface that creates and modifies network policy rules.
|
||||
* <p/>
|
||||
* {@hide}
|
||||
*/
|
||||
public interface INetworkPolicyManager extends android.os.IInterface {
|
||||
/**
|
||||
* Local-side IPC implementation stub class.
|
||||
*/
|
||||
public static abstract class Stub extends android.os.Binder implements android.net.INetworkPolicyManager {
|
||||
private static final java.lang.String DESCRIPTOR = "android.net.INetworkPolicyManager";
|
||||
|
||||
/**
|
||||
* Construct the stub at attach it to the interface.
|
||||
*/
|
||||
public Stub() {
|
||||
this.attachInterface(this, DESCRIPTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast an IBinder object into an android.net.INetworkPolicyManager interface,
|
||||
* generating a proxy if needed.
|
||||
*/
|
||||
public static android.net.INetworkPolicyManager asInterface(android.os.IBinder obj) {
|
||||
if ((obj == null)) {
|
||||
return null;
|
||||
}
|
||||
android.os.IInterface iin = obj.queryLocalInterface(DESCRIPTOR);
|
||||
if (((iin != null) && (iin instanceof android.net.INetworkPolicyManager))) {
|
||||
return ((android.net.INetworkPolicyManager) iin);
|
||||
}
|
||||
return new android.net.INetworkPolicyManager.Stub.Proxy(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.os.IBinder asBinder() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException {
|
||||
switch (code) {
|
||||
case INTERFACE_TRANSACTION: {
|
||||
reply.writeString(DESCRIPTOR);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_setUidPolicy: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
int _arg0;
|
||||
_arg0 = data.readInt();
|
||||
int _arg1;
|
||||
_arg1 = data.readInt();
|
||||
this.setUidPolicy(_arg0, _arg1);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getUidPolicy: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
int _arg0;
|
||||
_arg0 = data.readInt();
|
||||
int _result = this.getUidPolicy(_arg0);
|
||||
reply.writeNoException();
|
||||
reply.writeInt(_result);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getUidsWithPolicy: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
int _arg0;
|
||||
_arg0 = data.readInt();
|
||||
int[] _result = this.getUidsWithPolicy(_arg0);
|
||||
reply.writeNoException();
|
||||
reply.writeIntArray(_result);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_isUidForeground: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
int _arg0;
|
||||
_arg0 = data.readInt();
|
||||
boolean _result = this.isUidForeground(_arg0);
|
||||
reply.writeNoException();
|
||||
reply.writeInt(((_result) ? (1) : (0)));
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_registerListener: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.INetworkPolicyListener _arg0;
|
||||
_arg0 = android.net.INetworkPolicyListener.Stub.asInterface(data.readStrongBinder());
|
||||
this.registerListener(_arg0);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_unregisterListener: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.INetworkPolicyListener _arg0;
|
||||
_arg0 = android.net.INetworkPolicyListener.Stub.asInterface(data.readStrongBinder());
|
||||
this.unregisterListener(_arg0);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_setNetworkPolicies: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.NetworkPolicy[] _arg0;
|
||||
_arg0 = data.createTypedArray(android.net.NetworkPolicy.CREATOR);
|
||||
this.setNetworkPolicies(_arg0);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getNetworkPolicies: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.NetworkPolicy[] _result = this.getNetworkPolicies();
|
||||
reply.writeNoException();
|
||||
reply.writeTypedArray(_result, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_snoozeLimit: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.NetworkTemplate _arg0;
|
||||
if ((0 != data.readInt())) {
|
||||
_arg0 = android.net.NetworkTemplate.CREATOR.createFromParcel(data);
|
||||
} else {
|
||||
_arg0 = null;
|
||||
}
|
||||
this.snoozeLimit(_arg0);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_setRestrictBackground: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
boolean _arg0;
|
||||
_arg0 = (0 != data.readInt());
|
||||
this.setRestrictBackground(_arg0);
|
||||
reply.writeNoException();
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getRestrictBackground: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
boolean _result = this.getRestrictBackground();
|
||||
reply.writeNoException();
|
||||
reply.writeInt(((_result) ? (1) : (0)));
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_getNetworkQuotaInfo: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.NetworkState _arg0;
|
||||
if ((0 != data.readInt())) {
|
||||
_arg0 = android.net.NetworkState.CREATOR.createFromParcel(data);
|
||||
} else {
|
||||
_arg0 = null;
|
||||
}
|
||||
android.net.NetworkQuotaInfo _result = this.getNetworkQuotaInfo(_arg0);
|
||||
reply.writeNoException();
|
||||
if ((_result != null)) {
|
||||
reply.writeInt(1);
|
||||
_result.writeToParcel(reply, android.os.Parcelable.PARCELABLE_WRITE_RETURN_VALUE);
|
||||
} else {
|
||||
reply.writeInt(0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case TRANSACTION_isNetworkMetered: {
|
||||
data.enforceInterface(DESCRIPTOR);
|
||||
android.net.NetworkState _arg0;
|
||||
if ((0 != data.readInt())) {
|
||||
_arg0 = android.net.NetworkState.CREATOR.createFromParcel(data);
|
||||
} else {
|
||||
_arg0 = null;
|
||||
}
|
||||
boolean _result = this.isNetworkMetered(_arg0);
|
||||
reply.writeNoException();
|
||||
reply.writeInt(((_result) ? (1) : (0)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onTransact(code, data, reply, flags);
|
||||
}
|
||||
|
||||
private static class Proxy implements android.net.INetworkPolicyManager {
|
||||
private android.os.IBinder mRemote;
|
||||
|
||||
Proxy(android.os.IBinder remote) {
|
||||
mRemote = remote;
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.os.IBinder asBinder() {
|
||||
return mRemote;
|
||||
}
|
||||
|
||||
/**
|
||||
* Control UID policies.
|
||||
*/
|
||||
@Override
|
||||
public void setUidPolicy(int uid, int policy) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(uid);
|
||||
_data.writeInt(policy);
|
||||
mRemote.transact(Stub.TRANSACTION_setUidPolicy, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUidPolicy(int uid) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
int _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(uid);
|
||||
mRemote.transact(Stub.TRANSACTION_getUidPolicy, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = _reply.readInt();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getUidsWithPolicy(int policy) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
int[] _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(policy);
|
||||
mRemote.transact(Stub.TRANSACTION_getUidsWithPolicy, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = _reply.createIntArray();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUidForeground(int uid) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
boolean _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(uid);
|
||||
mRemote.transact(Stub.TRANSACTION_isUidForeground, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = (0 != _reply.readInt());
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerListener(android.net.INetworkPolicyListener listener) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeStrongBinder((((listener != null)) ? (listener.asBinder()) : (null)));
|
||||
mRemote.transact(Stub.TRANSACTION_registerListener, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterListener(android.net.INetworkPolicyListener listener) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeStrongBinder((((listener != null)) ? (listener.asBinder()) : (null)));
|
||||
mRemote.transact(Stub.TRANSACTION_unregisterListener, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Control network policies atomically.
|
||||
*/
|
||||
@Override
|
||||
public void setNetworkPolicies(android.net.NetworkPolicy[] policies) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeTypedArray(policies, 0);
|
||||
mRemote.transact(Stub.TRANSACTION_setNetworkPolicies, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.net.NetworkPolicy[] getNetworkPolicies() throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
android.net.NetworkPolicy[] _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
mRemote.transact(Stub.TRANSACTION_getNetworkPolicies, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = _reply.createTypedArray(android.net.NetworkPolicy.CREATOR);
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Snooze limit on policy matching given template.
|
||||
*/
|
||||
@Override
|
||||
public void snoozeLimit(android.net.NetworkTemplate template) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
if ((template != null)) {
|
||||
_data.writeInt(1);
|
||||
template.writeToParcel(_data, 0);
|
||||
} else {
|
||||
_data.writeInt(0);
|
||||
}
|
||||
mRemote.transact(Stub.TRANSACTION_snoozeLimit, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Control if background data is restricted system-wide.
|
||||
*/
|
||||
@Override
|
||||
public void setRestrictBackground(boolean restrictBackground) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
_data.writeInt(((restrictBackground) ? (1) : (0)));
|
||||
mRemote.transact(Stub.TRANSACTION_setRestrictBackground, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getRestrictBackground() throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
boolean _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
mRemote.transact(Stub.TRANSACTION_getRestrictBackground, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = (0 != _reply.readInt());
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public android.net.NetworkQuotaInfo getNetworkQuotaInfo(android.net.NetworkState state) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
android.net.NetworkQuotaInfo _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
if ((state != null)) {
|
||||
_data.writeInt(1);
|
||||
state.writeToParcel(_data, 0);
|
||||
} else {
|
||||
_data.writeInt(0);
|
||||
}
|
||||
mRemote.transact(Stub.TRANSACTION_getNetworkQuotaInfo, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
if ((0 != _reply.readInt())) {
|
||||
_result = android.net.NetworkQuotaInfo.CREATOR.createFromParcel(_reply);
|
||||
} else {
|
||||
_result = null;
|
||||
}
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNetworkMetered(android.net.NetworkState state) throws android.os.RemoteException {
|
||||
android.os.Parcel _data = android.os.Parcel.obtain();
|
||||
android.os.Parcel _reply = android.os.Parcel.obtain();
|
||||
boolean _result;
|
||||
try {
|
||||
_data.writeInterfaceToken(DESCRIPTOR);
|
||||
if ((state != null)) {
|
||||
_data.writeInt(1);
|
||||
state.writeToParcel(_data, 0);
|
||||
} else {
|
||||
_data.writeInt(0);
|
||||
}
|
||||
mRemote.transact(Stub.TRANSACTION_isNetworkMetered, _data, _reply, 0);
|
||||
_reply.readException();
|
||||
_result = (0 != _reply.readInt());
|
||||
} finally {
|
||||
_reply.recycle();
|
||||
_data.recycle();
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
}
|
||||
|
||||
static final int TRANSACTION_setUidPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
|
||||
static final int TRANSACTION_getUidPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION + 1);
|
||||
static final int TRANSACTION_getUidsWithPolicy = (android.os.IBinder.FIRST_CALL_TRANSACTION + 2);
|
||||
static final int TRANSACTION_isUidForeground = (android.os.IBinder.FIRST_CALL_TRANSACTION + 3);
|
||||
static final int TRANSACTION_registerListener = (android.os.IBinder.FIRST_CALL_TRANSACTION + 4);
|
||||
static final int TRANSACTION_unregisterListener = (android.os.IBinder.FIRST_CALL_TRANSACTION + 5);
|
||||
static final int TRANSACTION_setNetworkPolicies = (android.os.IBinder.FIRST_CALL_TRANSACTION + 6);
|
||||
static final int TRANSACTION_getNetworkPolicies = (android.os.IBinder.FIRST_CALL_TRANSACTION + 7);
|
||||
static final int TRANSACTION_snoozeLimit = (android.os.IBinder.FIRST_CALL_TRANSACTION + 8);
|
||||
static final int TRANSACTION_setRestrictBackground = (android.os.IBinder.FIRST_CALL_TRANSACTION + 9);
|
||||
static final int TRANSACTION_getRestrictBackground = (android.os.IBinder.FIRST_CALL_TRANSACTION + 10);
|
||||
static final int TRANSACTION_getNetworkQuotaInfo = (android.os.IBinder.FIRST_CALL_TRANSACTION + 11);
|
||||
static final int TRANSACTION_isNetworkMetered = (android.os.IBinder.FIRST_CALL_TRANSACTION + 12);
|
||||
}
|
||||
|
||||
/**
|
||||
* Control UID policies.
|
||||
*/
|
||||
public void setUidPolicy(int uid, int policy) throws android.os.RemoteException;
|
||||
|
||||
public int getUidPolicy(int uid) throws android.os.RemoteException;
|
||||
|
||||
public int[] getUidsWithPolicy(int policy) throws android.os.RemoteException;
|
||||
|
||||
public boolean isUidForeground(int uid) throws android.os.RemoteException;
|
||||
|
||||
public void registerListener(android.net.INetworkPolicyListener listener) throws android.os.RemoteException;
|
||||
|
||||
public void unregisterListener(android.net.INetworkPolicyListener listener) throws android.os.RemoteException;
|
||||
|
||||
/**
|
||||
* Control network policies atomically.
|
||||
*/
|
||||
public void setNetworkPolicies(android.net.NetworkPolicy[] policies) throws android.os.RemoteException;
|
||||
|
||||
public android.net.NetworkPolicy[] getNetworkPolicies() throws android.os.RemoteException;
|
||||
|
||||
/**
|
||||
* Snooze limit on policy matching given template.
|
||||
*/
|
||||
public void snoozeLimit(android.net.NetworkTemplate template) throws android.os.RemoteException;
|
||||
|
||||
/**
|
||||
* Control if background data is restricted system-wide.
|
||||
*/
|
||||
public void setRestrictBackground(boolean restrictBackground) throws android.os.RemoteException;
|
||||
|
||||
public boolean getRestrictBackground() throws android.os.RemoteException;
|
||||
|
||||
public android.net.NetworkQuotaInfo getNetworkQuotaInfo(android.net.NetworkState state) throws android.os.RemoteException;
|
||||
|
||||
public boolean isNetworkMetered(android.net.NetworkState state) throws android.os.RemoteException;
|
||||
}
|
||||
@@ -1,193 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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.net;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import com.android.internal.util.Objects;
|
||||
|
||||
import static com.android.internal.util.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Policy for networks matching a {@link NetworkTemplate}, including usage cycle
|
||||
* and limits to be enforced.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class NetworkPolicy implements Parcelable, Comparable<NetworkPolicy> {
|
||||
public static final int CYCLE_NONE = -1;
|
||||
public static final long WARNING_DISABLED = -1;
|
||||
public static final long LIMIT_DISABLED = -1;
|
||||
public static final long SNOOZE_NEVER = -1;
|
||||
|
||||
public final NetworkTemplate template;
|
||||
public int cycleDay;
|
||||
public String cycleTimezone;
|
||||
public long warningBytes;
|
||||
public long limitBytes;
|
||||
public long lastWarningSnooze;
|
||||
public long lastLimitSnooze;
|
||||
public boolean metered;
|
||||
public boolean inferred;
|
||||
|
||||
private static final long DEFAULT_MTU = 1500;
|
||||
|
||||
@Deprecated
|
||||
public NetworkPolicy(NetworkTemplate template, int cycleDay, String cycleTimezone,
|
||||
long warningBytes, long limitBytes, boolean metered) {
|
||||
this(template, cycleDay, cycleTimezone, warningBytes, limitBytes, SNOOZE_NEVER,
|
||||
SNOOZE_NEVER, metered, false);
|
||||
}
|
||||
|
||||
public NetworkPolicy(NetworkTemplate template, int cycleDay, String cycleTimezone,
|
||||
long warningBytes, long limitBytes, long lastWarningSnooze, long lastLimitSnooze,
|
||||
boolean metered, boolean inferred) {
|
||||
this.template = checkNotNull(template, "missing NetworkTemplate");
|
||||
this.cycleDay = cycleDay;
|
||||
this.cycleTimezone = checkNotNull(cycleTimezone, "missing cycleTimezone");
|
||||
this.warningBytes = warningBytes;
|
||||
this.limitBytes = limitBytes;
|
||||
this.lastWarningSnooze = lastWarningSnooze;
|
||||
this.lastLimitSnooze = lastLimitSnooze;
|
||||
this.metered = metered;
|
||||
this.inferred = inferred;
|
||||
}
|
||||
|
||||
public NetworkPolicy(Parcel in) {
|
||||
template = in.readParcelable(null);
|
||||
cycleDay = in.readInt();
|
||||
cycleTimezone = in.readString();
|
||||
warningBytes = in.readLong();
|
||||
limitBytes = in.readLong();
|
||||
lastWarningSnooze = in.readLong();
|
||||
lastLimitSnooze = in.readLong();
|
||||
metered = in.readInt() != 0;
|
||||
inferred = in.readInt() != 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeParcelable(template, flags);
|
||||
dest.writeInt(cycleDay);
|
||||
dest.writeString(cycleTimezone);
|
||||
dest.writeLong(warningBytes);
|
||||
dest.writeLong(limitBytes);
|
||||
dest.writeLong(lastWarningSnooze);
|
||||
dest.writeLong(lastLimitSnooze);
|
||||
dest.writeInt(metered ? 1 : 0);
|
||||
dest.writeInt(inferred ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if given measurement is over {@link #warningBytes}.
|
||||
*/
|
||||
public boolean isOverWarning(long totalBytes) {
|
||||
return warningBytes != WARNING_DISABLED && totalBytes >= warningBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if given measurement is near enough to {@link #limitBytes} to be
|
||||
* considered over-limit.
|
||||
*/
|
||||
public boolean isOverLimit(long totalBytes) {
|
||||
// over-estimate, since kernel will trigger limit once first packet
|
||||
// trips over limit.
|
||||
totalBytes += 2 * DEFAULT_MTU;
|
||||
return limitBytes != LIMIT_DISABLED && totalBytes >= limitBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear any existing snooze values, setting to {@link #SNOOZE_NEVER}.
|
||||
*/
|
||||
public void clearSnooze() {
|
||||
lastWarningSnooze = SNOOZE_NEVER;
|
||||
lastLimitSnooze = SNOOZE_NEVER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if this policy has a cycle defined, after which usage should reset.
|
||||
*/
|
||||
public boolean hasCycle() {
|
||||
return cycleDay != CYCLE_NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(NetworkPolicy another) {
|
||||
if (another == null || another.limitBytes == LIMIT_DISABLED) {
|
||||
// other value is missing or disabled; we win
|
||||
return -1;
|
||||
}
|
||||
if (limitBytes == LIMIT_DISABLED || another.limitBytes < limitBytes) {
|
||||
// we're disabled or other limit is smaller; they win
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(template, cycleDay, cycleTimezone, warningBytes, limitBytes,
|
||||
lastWarningSnooze, lastLimitSnooze, metered, inferred);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof NetworkPolicy) {
|
||||
final NetworkPolicy other = (NetworkPolicy) obj;
|
||||
return cycleDay == other.cycleDay && warningBytes == other.warningBytes
|
||||
&& limitBytes == other.limitBytes
|
||||
&& lastWarningSnooze == other.lastWarningSnooze
|
||||
&& lastLimitSnooze == other.lastLimitSnooze && metered == other.metered
|
||||
&& inferred == other.inferred
|
||||
&& Objects.equal(cycleTimezone, other.cycleTimezone)
|
||||
&& Objects.equal(template, other.template);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder("NetworkPolicy");
|
||||
builder.append("[").append(template).append("]:");
|
||||
builder.append(" cycleDay=").append(cycleDay);
|
||||
builder.append(", cycleTimezone=").append(cycleTimezone);
|
||||
builder.append(", warningBytes=").append(warningBytes);
|
||||
builder.append(", limitBytes=").append(limitBytes);
|
||||
builder.append(", lastWarningSnooze=").append(lastWarningSnooze);
|
||||
builder.append(", lastLimitSnooze=").append(lastLimitSnooze);
|
||||
builder.append(", metered=").append(metered);
|
||||
builder.append(", inferred=").append(inferred);
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public static final Creator<NetworkPolicy> CREATOR = new Creator<NetworkPolicy>() {
|
||||
@Override
|
||||
public NetworkPolicy createFromParcel(Parcel in) {
|
||||
return new NetworkPolicy(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkPolicy[] newArray(int size) {
|
||||
return new NetworkPolicy[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,293 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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.net;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.Signature;
|
||||
import android.os.RemoteException;
|
||||
import android.text.format.Time;
|
||||
import com.google.android.collect.Sets;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashSet;
|
||||
|
||||
import static android.content.pm.PackageManager.GET_SIGNATURES;
|
||||
import static android.net.NetworkPolicy.CYCLE_NONE;
|
||||
import static android.text.format.Time.MONTH_DAY;
|
||||
|
||||
/**
|
||||
* Manager for creating and modifying network policy rules.
|
||||
* <p/>
|
||||
* {@hide}
|
||||
*/
|
||||
public class NetworkPolicyManager {
|
||||
|
||||
/**
|
||||
* No specific network policy, use system default.
|
||||
*/
|
||||
public static final int POLICY_NONE = 0x0;
|
||||
/**
|
||||
* Reject network usage on metered networks when application in background.
|
||||
*/
|
||||
public static final int POLICY_REJECT_METERED_BACKGROUND = 0x1;
|
||||
|
||||
/**
|
||||
* All network traffic should be allowed.
|
||||
*/
|
||||
public static final int RULE_ALLOW_ALL = 0x0;
|
||||
/**
|
||||
* Reject traffic on metered networks.
|
||||
*/
|
||||
public static final int RULE_REJECT_METERED = 0x1;
|
||||
|
||||
private static final boolean ALLOW_PLATFORM_APP_POLICY = true;
|
||||
|
||||
/**
|
||||
* {@link Intent} extra that indicates which {@link NetworkTemplate} rule it
|
||||
* applies to.
|
||||
*/
|
||||
public static final String EXTRA_NETWORK_TEMPLATE = "android.net.NETWORK_TEMPLATE";
|
||||
|
||||
private INetworkPolicyManager mService;
|
||||
|
||||
public NetworkPolicyManager(INetworkPolicyManager service) {
|
||||
if (service == null) {
|
||||
throw new IllegalArgumentException("missing INetworkPolicyManager");
|
||||
}
|
||||
mService = service;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set policy flags for specific UID.
|
||||
*
|
||||
* @param policy {@link #POLICY_NONE} or combination of flags like
|
||||
* {@link #POLICY_REJECT_METERED_BACKGROUND}.
|
||||
*/
|
||||
public void setUidPolicy(int uid, int policy) {
|
||||
try {
|
||||
mService.setUidPolicy(uid, policy);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public int getUidPolicy(int uid) {
|
||||
try {
|
||||
return mService.getUidPolicy(uid);
|
||||
} catch (RemoteException e) {
|
||||
return POLICY_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
public int[] getUidsWithPolicy(int policy) {
|
||||
try {
|
||||
return mService.getUidsWithPolicy(policy);
|
||||
} catch (RemoteException e) {
|
||||
return new int[0];
|
||||
}
|
||||
}
|
||||
|
||||
public void registerListener(INetworkPolicyListener listener) {
|
||||
try {
|
||||
mService.registerListener(listener);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterListener(INetworkPolicyListener listener) {
|
||||
try {
|
||||
mService.unregisterListener(listener);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void setNetworkPolicies(NetworkPolicy[] policies) {
|
||||
try {
|
||||
mService.setNetworkPolicies(policies);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public NetworkPolicy[] getNetworkPolicies() {
|
||||
try {
|
||||
return mService.getNetworkPolicies();
|
||||
} catch (RemoteException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setRestrictBackground(boolean restrictBackground) {
|
||||
try {
|
||||
mService.setRestrictBackground(restrictBackground);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getRestrictBackground() {
|
||||
try {
|
||||
return mService.getRestrictBackground();
|
||||
} catch (RemoteException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the last cycle boundary for the given {@link NetworkPolicy}. For
|
||||
* example, if cycle day is 20th, and today is June 15th, it will return May
|
||||
* 20th. When cycle day doesn't exist in current month, it snaps to the 1st
|
||||
* of following month.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static long computeLastCycleBoundary(long currentTime, NetworkPolicy policy) {
|
||||
if (policy.cycleDay == CYCLE_NONE) {
|
||||
throw new IllegalArgumentException("Unable to compute boundary without cycleDay");
|
||||
}
|
||||
|
||||
final Time now = new Time(policy.cycleTimezone);
|
||||
now.set(currentTime);
|
||||
|
||||
// first, find cycle boundary for current month
|
||||
final Time cycle = new Time(now);
|
||||
cycle.hour = cycle.minute = cycle.second = 0;
|
||||
snapToCycleDay(cycle, policy.cycleDay);
|
||||
|
||||
if (Time.compare(cycle, now) >= 0) {
|
||||
// cycle boundary is beyond now, use last cycle boundary; start by
|
||||
// pushing ourselves squarely into last month.
|
||||
final Time lastMonth = new Time(now);
|
||||
lastMonth.hour = lastMonth.minute = lastMonth.second = 0;
|
||||
lastMonth.monthDay = 1;
|
||||
lastMonth.month -= 1;
|
||||
lastMonth.normalize(true);
|
||||
|
||||
cycle.set(lastMonth);
|
||||
snapToCycleDay(cycle, policy.cycleDay);
|
||||
}
|
||||
|
||||
return cycle.toMillis(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
public static long computeNextCycleBoundary(long currentTime, NetworkPolicy policy) {
|
||||
if (policy.cycleDay == CYCLE_NONE) {
|
||||
throw new IllegalArgumentException("Unable to compute boundary without cycleDay");
|
||||
}
|
||||
|
||||
final Time now = new Time(policy.cycleTimezone);
|
||||
now.set(currentTime);
|
||||
|
||||
// first, find cycle boundary for current month
|
||||
final Time cycle = new Time(now);
|
||||
cycle.hour = cycle.minute = cycle.second = 0;
|
||||
snapToCycleDay(cycle, policy.cycleDay);
|
||||
|
||||
if (Time.compare(cycle, now) <= 0) {
|
||||
// cycle boundary is before now, use next cycle boundary; start by
|
||||
// pushing ourselves squarely into next month.
|
||||
final Time nextMonth = new Time(now);
|
||||
nextMonth.hour = nextMonth.minute = nextMonth.second = 0;
|
||||
nextMonth.monthDay = 1;
|
||||
nextMonth.month += 1;
|
||||
nextMonth.normalize(true);
|
||||
|
||||
cycle.set(nextMonth);
|
||||
snapToCycleDay(cycle, policy.cycleDay);
|
||||
}
|
||||
|
||||
return cycle.toMillis(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Snap to the cycle day for the current month given; when cycle day doesn't
|
||||
* exist, it snaps to last second of current month.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static void snapToCycleDay(Time time, int cycleDay) {
|
||||
if (cycleDay > time.getActualMaximum(MONTH_DAY)) {
|
||||
// cycle day isn't valid this month; snap to last second of month
|
||||
time.month += 1;
|
||||
time.monthDay = 1;
|
||||
time.second = -1;
|
||||
} else {
|
||||
time.monthDay = cycleDay;
|
||||
}
|
||||
time.normalize(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if given UID can have a {@link #setUidPolicy(int, int)} defined,
|
||||
* usually to protect critical system services.
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isUidValidForPolicy(Context context, int uid) {
|
||||
|
||||
if (!ALLOW_PLATFORM_APP_POLICY) {
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
final HashSet<Signature> systemSignature;
|
||||
try {
|
||||
systemSignature = Sets.newHashSet(
|
||||
pm.getPackageInfo("android", GET_SIGNATURES).signatures);
|
||||
} catch (NameNotFoundException e) {
|
||||
throw new RuntimeException("problem finding system signature", e);
|
||||
}
|
||||
|
||||
try {
|
||||
// reject apps signed with platform cert
|
||||
for (String packageName : pm.getPackagesForUid(uid)) {
|
||||
final HashSet<Signature> packageSignature = Sets.newHashSet(
|
||||
pm.getPackageInfo(packageName, GET_SIGNATURES).signatures);
|
||||
if (packageSignature.containsAll(systemSignature)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} catch (NameNotFoundException e) {
|
||||
}
|
||||
}
|
||||
|
||||
// nothing found above; we can apply policy to UID
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
public static void dumpPolicy(PrintWriter fout, int policy) {
|
||||
fout.write("[");
|
||||
if ((policy & POLICY_REJECT_METERED_BACKGROUND) != 0) {
|
||||
fout.write("REJECT_METERED_BACKGROUND");
|
||||
}
|
||||
fout.write("]");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
public static void dumpRules(PrintWriter fout, int rules) {
|
||||
fout.write("[");
|
||||
if ((rules & RULE_REJECT_METERED) != 0) {
|
||||
fout.write("REJECT_METERED");
|
||||
}
|
||||
fout.write("]");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,455 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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.net;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.Objects;
|
||||
|
||||
import static android.net.ConnectivityManager.TYPE_ETHERNET;
|
||||
import static android.net.ConnectivityManager.TYPE_WIFI;
|
||||
import static android.net.ConnectivityManager.TYPE_WIMAX;
|
||||
import static android.net.NetworkIdentity.COMBINE_SUBTYPE_ENABLED;
|
||||
import static android.net.NetworkIdentity.scrubSubscriberId;
|
||||
import static com.android.internal.util.ArrayUtils.contains;
|
||||
|
||||
/**
|
||||
* Template definition used to generically match {@link NetworkIdentity},
|
||||
* usually when collecting statistics.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public class NetworkTemplate implements Parcelable {
|
||||
|
||||
public static final int MATCH_MOBILE_ALL = 1;
|
||||
public static final int MATCH_MOBILE_3G_LOWER = 2;
|
||||
public static final int MATCH_MOBILE_4G = 3;
|
||||
public static final int MATCH_WIFI = 4;
|
||||
public static final int MATCH_ETHERNET = 5;
|
||||
public static final int MATCH_MOBILE_WILDCARD = 6;
|
||||
public static final int MATCH_WIFI_WILDCARD = 7;
|
||||
|
||||
/**
|
||||
* Network type is unknown
|
||||
*/
|
||||
public static final int NETWORK_TYPE_UNKNOWN = 0;
|
||||
/**
|
||||
* Current network is GPRS
|
||||
*/
|
||||
public static final int NETWORK_TYPE_GPRS = 1;
|
||||
/**
|
||||
* Current network is EDGE
|
||||
*/
|
||||
public static final int NETWORK_TYPE_EDGE = 2;
|
||||
/**
|
||||
* Current network is UMTS
|
||||
*/
|
||||
public static final int NETWORK_TYPE_UMTS = 3;
|
||||
/**
|
||||
* Current network is CDMA: Either IS95A or IS95B
|
||||
*/
|
||||
public static final int NETWORK_TYPE_CDMA = 4;
|
||||
/**
|
||||
* Current network is EVDO revision 0
|
||||
*/
|
||||
public static final int NETWORK_TYPE_EVDO_0 = 5;
|
||||
/**
|
||||
* Current network is EVDO revision A
|
||||
*/
|
||||
public static final int NETWORK_TYPE_EVDO_A = 6;
|
||||
/**
|
||||
* Current network is 1xRTT
|
||||
*/
|
||||
public static final int NETWORK_TYPE_1xRTT = 7;
|
||||
/**
|
||||
* Current network is HSDPA
|
||||
*/
|
||||
public static final int NETWORK_TYPE_HSDPA = 8;
|
||||
/**
|
||||
* Current network is HSUPA
|
||||
*/
|
||||
public static final int NETWORK_TYPE_HSUPA = 9;
|
||||
/**
|
||||
* Current network is HSPA
|
||||
*/
|
||||
public static final int NETWORK_TYPE_HSPA = 10;
|
||||
/**
|
||||
* Current network is iDen
|
||||
*/
|
||||
public static final int NETWORK_TYPE_IDEN = 11;
|
||||
/**
|
||||
* Current network is EVDO revision B
|
||||
*/
|
||||
public static final int NETWORK_TYPE_EVDO_B = 12;
|
||||
/**
|
||||
* Current network is LTE
|
||||
*/
|
||||
public static final int NETWORK_TYPE_LTE = 13;
|
||||
/**
|
||||
* Current network is eHRPD
|
||||
*/
|
||||
public static final int NETWORK_TYPE_EHRPD = 14;
|
||||
/**
|
||||
* Current network is HSPA+
|
||||
*/
|
||||
public static final int NETWORK_TYPE_HSPAP = 15;
|
||||
|
||||
/**
|
||||
* Unknown network class. {@hide}
|
||||
*/
|
||||
public static final int NETWORK_CLASS_UNKNOWN = 0;
|
||||
/**
|
||||
* Class of broadly defined "2G" networks. {@hide}
|
||||
*/
|
||||
public static final int NETWORK_CLASS_2_G = 1;
|
||||
/**
|
||||
* Class of broadly defined "3G" networks. {@hide}
|
||||
*/
|
||||
public static final int NETWORK_CLASS_3_G = 2;
|
||||
/**
|
||||
* Class of broadly defined "4G" networks. {@hide}
|
||||
*/
|
||||
public static final int NETWORK_CLASS_4_G = 3;
|
||||
|
||||
/**
|
||||
* Return general class of network type, such as "3G" or "4G". In cases
|
||||
* where classification is contentious, this method is conservative.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static int getNetworkClass(int networkType) {
|
||||
switch (networkType) {
|
||||
case NETWORK_TYPE_GPRS:
|
||||
case NETWORK_TYPE_EDGE:
|
||||
case NETWORK_TYPE_CDMA:
|
||||
case NETWORK_TYPE_1xRTT:
|
||||
case NETWORK_TYPE_IDEN:
|
||||
return NETWORK_CLASS_2_G;
|
||||
case NETWORK_TYPE_UMTS:
|
||||
case NETWORK_TYPE_EVDO_0:
|
||||
case NETWORK_TYPE_EVDO_A:
|
||||
case NETWORK_TYPE_HSDPA:
|
||||
case NETWORK_TYPE_HSUPA:
|
||||
case NETWORK_TYPE_HSPA:
|
||||
case NETWORK_TYPE_EVDO_B:
|
||||
case NETWORK_TYPE_EHRPD:
|
||||
case NETWORK_TYPE_HSPAP:
|
||||
return NETWORK_CLASS_3_G;
|
||||
case NETWORK_TYPE_LTE:
|
||||
return NETWORK_CLASS_4_G;
|
||||
default:
|
||||
return NETWORK_CLASS_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set of {@link NetworkInfo#getType()} that reflect data usage.
|
||||
*/
|
||||
private static final int[] DATA_USAGE_NETWORK_TYPES = {0};
|
||||
|
||||
private static boolean sForceAllNetworkTypes = false;
|
||||
|
||||
@VisibleForTesting
|
||||
public static void forceAllNetworkTypes() {
|
||||
sForceAllNetworkTypes = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
|
||||
* the given IMSI.
|
||||
*/
|
||||
public static NetworkTemplate buildTemplateMobileAll(String subscriberId) {
|
||||
return new NetworkTemplate(MATCH_MOBILE_ALL, subscriberId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
|
||||
* the given IMSI that roughly meet a "3G" definition, or lower.
|
||||
*/
|
||||
@Deprecated
|
||||
public static NetworkTemplate buildTemplateMobile3gLower(String subscriberId) {
|
||||
return new NetworkTemplate(MATCH_MOBILE_3G_LOWER, subscriberId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks with
|
||||
* the given IMSI that roughly meet a "4G" definition.
|
||||
*/
|
||||
@Deprecated
|
||||
public static NetworkTemplate buildTemplateMobile4g(String subscriberId) {
|
||||
return new NetworkTemplate(MATCH_MOBILE_4G, subscriberId, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match {@link ConnectivityManager#TYPE_MOBILE} networks,
|
||||
* regardless of IMSI.
|
||||
*/
|
||||
public static NetworkTemplate buildTemplateMobileWildcard() {
|
||||
return new NetworkTemplate(MATCH_MOBILE_WILDCARD, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match all {@link ConnectivityManager#TYPE_WIFI} networks,
|
||||
* regardless of SSID.
|
||||
*/
|
||||
public static NetworkTemplate buildTemplateWifiWildcard() {
|
||||
return new NetworkTemplate(MATCH_WIFI_WILDCARD, null, null);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static NetworkTemplate buildTemplateWifi() {
|
||||
return buildTemplateWifiWildcard();
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to match {@link ConnectivityManager#TYPE_WIFI} networks with the
|
||||
* given SSID.
|
||||
*/
|
||||
public static NetworkTemplate buildTemplateWifi(String networkId) {
|
||||
return new NetworkTemplate(MATCH_WIFI, null, networkId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Template to combine all {@link ConnectivityManager#TYPE_ETHERNET} style
|
||||
* networks together.
|
||||
*/
|
||||
public static NetworkTemplate buildTemplateEthernet() {
|
||||
return new NetworkTemplate(MATCH_ETHERNET, null, null);
|
||||
}
|
||||
|
||||
private final int mMatchRule;
|
||||
private final String mSubscriberId;
|
||||
private final String mNetworkId;
|
||||
|
||||
public NetworkTemplate(int matchRule, String subscriberId, String networkId) {
|
||||
mMatchRule = matchRule;
|
||||
mSubscriberId = subscriberId;
|
||||
mNetworkId = networkId;
|
||||
}
|
||||
|
||||
private NetworkTemplate(Parcel in) {
|
||||
mMatchRule = in.readInt();
|
||||
mSubscriberId = in.readString();
|
||||
mNetworkId = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeInt(mMatchRule);
|
||||
dest.writeString(mSubscriberId);
|
||||
dest.writeString(mNetworkId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder("NetworkTemplate: ");
|
||||
builder.append("matchRule=").append(getMatchRuleName(mMatchRule));
|
||||
if (mSubscriberId != null) {
|
||||
builder.append(", subscriberId=").append(scrubSubscriberId(mSubscriberId));
|
||||
}
|
||||
if (mNetworkId != null) {
|
||||
builder.append(", networkId=").append(mNetworkId);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(mMatchRule, mSubscriberId, mNetworkId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof NetworkTemplate) {
|
||||
final NetworkTemplate other = (NetworkTemplate) obj;
|
||||
return mMatchRule == other.mMatchRule
|
||||
&& Objects.equal(mSubscriberId, other.mSubscriberId)
|
||||
&& Objects.equal(mNetworkId, other.mNetworkId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getMatchRule() {
|
||||
return mMatchRule;
|
||||
}
|
||||
|
||||
public String getSubscriberId() {
|
||||
return mSubscriberId;
|
||||
}
|
||||
|
||||
public String getNetworkId() {
|
||||
return mNetworkId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if given {@link NetworkIdentity} matches this template.
|
||||
*/
|
||||
public boolean matches(NetworkIdentity ident) {
|
||||
switch (mMatchRule) {
|
||||
case MATCH_MOBILE_ALL:
|
||||
return matchesMobile(ident);
|
||||
case MATCH_MOBILE_3G_LOWER:
|
||||
return matchesMobile3gLower(ident);
|
||||
case MATCH_MOBILE_4G:
|
||||
return matchesMobile4g(ident);
|
||||
case MATCH_WIFI:
|
||||
return matchesWifi(ident);
|
||||
case MATCH_ETHERNET:
|
||||
return matchesEthernet(ident);
|
||||
case MATCH_MOBILE_WILDCARD:
|
||||
return matchesMobileWildcard(ident);
|
||||
case MATCH_WIFI_WILDCARD:
|
||||
return matchesWifiWildcard(ident);
|
||||
default:
|
||||
throw new IllegalArgumentException("unknown network template");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mobile network with matching IMSI.
|
||||
*/
|
||||
private boolean matchesMobile(NetworkIdentity ident) {
|
||||
if (ident.mType == TYPE_WIMAX) {
|
||||
// TODO: consider matching against WiMAX subscriber identity
|
||||
return true;
|
||||
} else {
|
||||
return ((sForceAllNetworkTypes || contains(DATA_USAGE_NETWORK_TYPES, ident.mType))
|
||||
&& Objects.equal(mSubscriberId, ident.mSubscriberId));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mobile network classified 3G or lower with matching IMSI.
|
||||
*/
|
||||
private boolean matchesMobile3gLower(NetworkIdentity ident) {
|
||||
ensureSubtypeAvailable();
|
||||
if (ident.mType == TYPE_WIMAX) {
|
||||
return false;
|
||||
} else if (matchesMobile(ident)) {
|
||||
switch (getNetworkClass(ident.mSubType)) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if mobile network classified 4G with matching IMSI.
|
||||
*/
|
||||
private boolean matchesMobile4g(NetworkIdentity ident) {
|
||||
ensureSubtypeAvailable();
|
||||
if (ident.mType == TYPE_WIMAX) {
|
||||
// TODO: consider matching against WiMAX subscriber identity
|
||||
return true;
|
||||
} else if (matchesMobile(ident)) {
|
||||
switch (getNetworkClass(ident.mSubType)) {
|
||||
case 3:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if matches Wi-Fi network template.
|
||||
*/
|
||||
private boolean matchesWifi(NetworkIdentity ident) {
|
||||
switch (ident.mType) {
|
||||
case TYPE_WIFI:
|
||||
return Objects.equal(mNetworkId, ident.mNetworkId);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if matches Ethernet network template.
|
||||
*/
|
||||
private boolean matchesEthernet(NetworkIdentity ident) {
|
||||
if (ident.mType == TYPE_ETHERNET) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean matchesMobileWildcard(NetworkIdentity ident) {
|
||||
if (ident.mType == TYPE_WIMAX) {
|
||||
return true;
|
||||
} else {
|
||||
return sForceAllNetworkTypes || contains(DATA_USAGE_NETWORK_TYPES, ident.mType);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchesWifiWildcard(NetworkIdentity ident) {
|
||||
switch (ident.mType) {
|
||||
case TYPE_WIFI:
|
||||
case 13:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getMatchRuleName(int matchRule) {
|
||||
switch (matchRule) {
|
||||
case MATCH_MOBILE_3G_LOWER:
|
||||
return "MOBILE_3G_LOWER";
|
||||
case MATCH_MOBILE_4G:
|
||||
return "MOBILE_4G";
|
||||
case MATCH_MOBILE_ALL:
|
||||
return "MOBILE_ALL";
|
||||
case MATCH_WIFI:
|
||||
return "WIFI";
|
||||
case MATCH_ETHERNET:
|
||||
return "ETHERNET";
|
||||
case MATCH_MOBILE_WILDCARD:
|
||||
return "MOBILE_WILDCARD";
|
||||
case MATCH_WIFI_WILDCARD:
|
||||
return "WIFI_WILDCARD";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
private static void ensureSubtypeAvailable() {
|
||||
if (COMBINE_SUBTYPE_ENABLED) {
|
||||
throw new IllegalArgumentException(
|
||||
"Unable to enforce 3G_LOWER template on combined data.");
|
||||
}
|
||||
}
|
||||
|
||||
public static final Creator<NetworkTemplate> CREATOR = new Creator<NetworkTemplate>() {
|
||||
@Override
|
||||
public NetworkTemplate createFromParcel(Parcel in) {
|
||||
return new NetworkTemplate(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NetworkTemplate[] newArray(int size) {
|
||||
return new NetworkTemplate[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user