Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 902f08b5 authored by Steve Kondik's avatar Steve Kondik
Browse files

Cleanup after 2.3.4 merge

Change-Id: I654f10ea247e03a2d8172c1a6f1cb38382121df7
parent 18b7f3fc
Loading
Loading
Loading
Loading
+6 −119
Original line number Diff line number Diff line
@@ -51,11 +51,8 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
<<<<<<< HEAD
=======
import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;
>>>>>>> f0f1ceeb517ff226532a407da6d55602f195e5b5
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
@@ -111,14 +108,11 @@ public class ConnectivityService extends IConnectivityManager.Stub {

    private boolean mTestMode;
    private static ConnectivityService sServiceInstance;
<<<<<<< HEAD

    private boolean mWimaxConnected = false;
    private IBinder mWimaxService;
    private NetworkStateTracker mWimaxStateTracker;

=======
>>>>>>> f0f1ceeb517ff226532a407da6d55602f195e5b5
    private static final int ENABLED  = 1;
    private static final int DISABLED = 0;

@@ -399,18 +393,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                wst.startMonitoring();

                break;
            case ConnectivityManager.TYPE_WIMAX:
                // SystemProperties.set("wimax.dualmode", "1");
                // SystemProperties.set("wimax.dualmode.connect", "1");
                // SystemProperties.set("wimax.dualmode.1xrtt","0");
                // SystemProperties.set("wimax.wifi.disable","1");
                // SystemProperties.set("wimax.disable.delay","1");

                // start with wimax disabled for now
                final ContentResolver cr = mContext.getContentResolver();
                Settings.Secure.putInt(cr, Settings.Secure.WIMAX_ON, 0);
                startWimaxService();
                break;

            case ConnectivityManager.TYPE_MOBILE:
                mNetTrackers[netType] = new MobileDataStateTracker(context, mHandler,
@@ -422,6 +404,10 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                }
                break;
            case ConnectivityManager.TYPE_WIMAX:
               final ContentResolver cr = mContext.getContentResolver();
                Settings.Secure.putInt(cr, Settings.Secure.WIMAX_ON, 0);
                startWimaxService();

                NetworkStateTracker nst = makeWimaxStateTracker();
                if (nst != null) {
                    nst.startMonitoring();
@@ -451,7 +437,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        }
    }

<<<<<<< HEAD
    private void startWimaxService() {
        Slog.v(TAG, "Starting Wimax Service.");
        mWimaxStateTracker = createWimaxStateTracker(mContext, mHandler);
@@ -463,7 +448,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                mWimaxStateTracker.startMonitoring();
            }
        }
=======
    }

    private NetworkStateTracker makeWimaxStateTracker() {
        //Initialize Wimax
        DexClassLoader wimaxClassLoader;
@@ -551,7 +537,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        }

        return wimaxStateTracker;
>>>>>>> f0f1ceeb517ff226532a407da6d55602f195e5b5
    }

    /**
@@ -645,27 +630,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
     */
    public NetworkInfo getActiveNetworkInfo() {
        enforceAccessPermission();
<<<<<<< HEAD
        for (int type=0; type <= ConnectivityManager.MAX_NETWORK_TYPE; type++) {
            if (mNetAttributes[type] == null || !mNetAttributes[type].isDefault()) {
                continue;
            }
            NetworkStateTracker t = mNetTrackers[type];
            if (t != null) {
                NetworkInfo info = t.getNetworkInfo();
                if (info.isConnected()) {
                    if (DBG && type != mActiveDefaultNetwork) Slog.e(TAG,
                            "connected default network is not " +
                            "mActiveDefaultNetwork!");
                    return info;
                }
            } else {
                Slog.e(TAG, "Unable to get NetworkStateTracker for type=" + type);
            }
=======
        if (mActiveDefaultNetwork != -1) {
            return mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
>>>>>>> f0f1ceeb517ff226532a407da6d55602f195e5b5
        }
        return null;
    }
@@ -1195,36 +1161,9 @@ public class ConnectivityService extends IConnectivityManager.Stub {
        }

        if (mNetAttributes[prevNetType].isDefault()) {
<<<<<<< HEAD
            Slog.d(TAG, "ConnectivityService::handleDisconnect() - netType("
                + prevNetType + ") attempting failover");
        /*if (prevNetType == ConnectivityManager.TYPE_WIMAX) {
            System.out.println("ConnectivityService::handleDisconnect() - netType("
                + prevNetType + ") attempting to up 3g...");
            // hack to get rmnet0 back up
            setMobileDataEnabled(false);
            System.out.println("ConnectivityService::handleDisconnect() - netType("
                + prevNetType + ") data disabled...");
            setMobileDataEnabled(true);
            System.out.println("ConnectivityService::handleDisconnect() - netType("
                + prevNetType + ") data enabled...");
        } else*/
            newNet = tryFailover(prevNetType);
            if (newNet != null) {
            Slog.d(TAG, "ConnectivityService::handleDisconnect() - netType(" + prevNetType + ") failed over");
                NetworkInfo switchTo = newNet.getNetworkInfo();
                if (!switchTo.isConnected()) {
                    // if the other net is connected they've already reset this and perhaps even gotten
                    // a positive report we don't want to overwrite, but if not we need to clear this now
                    // to turn our cellular sig strength white
                    mDefaultInetConditionPublished = 0;
                    intent.putExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, true);
                }
=======
            tryFailover(prevNetType);
            if (mActiveDefaultNetwork != -1) {
                NetworkInfo switchTo = mNetTrackers[mActiveDefaultNetwork].getNetworkInfo();
>>>>>>> f0f1ceeb517ff226532a407da6d55602f195e5b5
                intent.putExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO, switchTo);
            } else {
                mDefaultInetConditionPublished = 0; // we're not connected anymore
@@ -1278,57 +1217,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                        continue;
                    //}
                }
<<<<<<< HEAD
                if (mNetAttributes[checkType].isDefault()) {
                    Slog.d(TAG, "ConnectivityService::tryFailover() - checkType[" + checkType
                        + " is default, network pref = " + mNetworkPreference);
                    /* TODO - if we have multiple nets we could use
                     * we may want to put more thought into which we choose
                     */
                    if (checkType == mNetworkPreference) {
                        newType = checkType;
                        break;
                    }
                    if (mNetAttributes[checkType].mPriority > newPriority) {
                        newType = checkType;
                        newPriority = mNetAttributes[newType].mPriority;
                    }
                }
            }

            if (newType != -1) {
                newNet = mNetTrackers[newType];
                /**
                 * See if the other network is available to fail over to.
                 * If is not available, we enable it anyway, so that it
                 * will be able to connect when it does become available,
                 * but we report a total loss of connectivity rather than
                 * report that we are attempting to fail over.
                 */
                if (newNet.isAvailable()) {
                    Slog.d(TAG, "ConnectivityService::tryFailover() - newNet is available");
                    NetworkInfo switchTo = newNet.getNetworkInfo();
                    switchTo.setFailover(true);
                    if (!switchTo.isConnectedOrConnecting() ||
                            newNet.isTeardownRequested()) {
                        newNet.reconnect();
                    }
                    if (DBG) {
                        if (switchTo.isConnected()) {
                            Slog.v(TAG, "Switching to already connected " +
                                    switchTo.getTypeName());
                        } else {
                            Slog.v(TAG, "Attempting to switch to " +
                                    switchTo.getTypeName());
                        }
                    }
                } else {
                    Slog.d(TAG, "ConnectivityService::tryFailover() - newNet NOT available!");
                    newNet.reconnect();
                    if (prevNetType != ConnectivityManager.TYPE_WIMAX) {
                        newNet = null; // not officially avail..  try anyway, but report no failover
                    }
=======
                if (mNetAttributes[checkType].mRadio == ConnectivityManager.TYPE_WIMAX &&
                        noMobileData) {
                    Slog.e(TAG, "not failing over to mobile type " + checkType +
@@ -1340,7 +1228,6 @@ public class ConnectivityService extends IConnectivityManager.Stub {
                if (!checkInfo.isConnectedOrConnecting() || checkTracker.isTeardownRequested()) {
                    checkInfo.setFailover(true);
                    checkTracker.reconnect();
>>>>>>> f0f1ceeb517ff226532a407da6d55602f195e5b5
                }
                if (DBG) Slog.d(TAG, "Attempting to switch to " + checkInfo.getTypeName());
            }
+0 −227
Original line number Diff line number Diff line
/*
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server;

import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.hardware.Usb;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.os.UEventObserver;
import android.provider.Settings;
import android.util.Log;
import android.util.Slog;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;

/**
 * <p>UsbObserver monitors for changes to USB state.
 */
class UsbObserver extends UEventObserver {
    private static final String TAG = UsbObserver.class.getSimpleName();
    private static final boolean LOG = false;

    private static final String USB_CONFIGURATION_MATCH = "DEVPATH=/devices/virtual/switch/usb_configuration";
    private static final String USB_FUNCTIONS_MATCH = "DEVPATH=/devices/virtual/usb_composite/";
    private static final String USB_CONFIGURATION_PATH = "/sys/class/switch/usb_configuration/state";
    private static final String USB_COMPOSITE_CLASS_PATH = "/sys/class/usb_composite";
    private static final String USB_CONFIGURATION_MATCH_LEGACY = "DEVPATH=/devices/virtual/switch/usb_mass_storage";

    private static final int MSG_UPDATE = 0;

    private int mUsbConfig = 0;
    private int mPreviousUsbConfig = 0;

    // lists of enabled and disabled USB functions
    private final ArrayList<String> mEnabledFunctions = new ArrayList<String>();
    private final ArrayList<String> mDisabledFunctions = new ArrayList<String>();

    private boolean mSystemReady;

    private final Context mContext;

    private PowerManagerService mPowerManager;

    public UsbObserver(Context context) {
        mContext = context;
        init();  // set initial status

        startObserving(USB_CONFIGURATION_MATCH);
        startObserving(USB_FUNCTIONS_MATCH);
        startObserving(USB_CONFIGURATION_MATCH_LEGACY);
    }

    @Override
    public void onUEvent(UEventObserver.UEvent event) {
        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Slog.v(TAG, "USB UEVENT: " + event.toString());
        }

        synchronized (this) {
            String switchState = event.get("SWITCH_STATE");
            if (switchState != null) {
                try {
                    int newConfig = Integer.parseInt(switchState);
                    if (newConfig != mUsbConfig) {
                        mPreviousUsbConfig = mUsbConfig;
                        mUsbConfig = newConfig;
                        // trigger an Intent broadcast
                        if (mSystemReady) {
                            update();
                        }
                    }
                } catch (NumberFormatException e) {
                    Slog.e(TAG, "Could not parse switch state from event " + event);
                    int newConfig = 0;
                    if (switchState.equals("offline")) {
                        newConfig = 0;
                    } else if (switchState.equals("online")) {
                        newConfig = 1;
                    }
                    if (newConfig != mUsbConfig) {
                        mPreviousUsbConfig = mUsbConfig;
                        mUsbConfig = newConfig;
                        // trigger an Intent broadcast
                        if (mSystemReady) {
                            update();
                        }
                    }
                }
            } else {
                String function = event.get("FUNCTION");
                String enabledStr = event.get("ENABLED");
                if (function != null && enabledStr != null) {
                    // Note: we do not broadcast a change when a function is enabled or disabled.
                    // We just record the state change for the next broadcast.
                    boolean enabled = "1".equals(enabledStr);
                    if (enabled) {
                        if (!mEnabledFunctions.contains(function)) {
                            mEnabledFunctions.add(function);
                        }
                        mDisabledFunctions.remove(function);
                    } else {
                        if (!mDisabledFunctions.contains(function)) {
                            mDisabledFunctions.add(function);
                        }
                        mEnabledFunctions.remove(function);
                    }
                }
            }
        }
    }
    private final void init() {
        char[] buffer = new char[1024];

        try {
            FileReader file = new FileReader(USB_CONFIGURATION_PATH);
            int len = file.read(buffer, 0, 1024);
            mPreviousUsbConfig = mUsbConfig = Integer.valueOf((new String(buffer, 0, len)).trim());

        } catch (FileNotFoundException e) {
            Slog.w(TAG, "This kernel does not have USB configuration switch support");
        } catch (Exception e) {
            Slog.e(TAG, "" , e);
        }

        try {
            File[] files = new File(USB_COMPOSITE_CLASS_PATH).listFiles();
            if (files != null) {
                for (int i = 0; i < files.length; i++) {
                    File file = new File(files[i], "enable");
                    FileReader reader = new FileReader(file);
                    int len = reader.read(buffer, 0, 1024);
                    int value = Integer.valueOf((new String(buffer, 0, len)).trim());
                    String functionName = files[i].getName();
                    if (value == 1) {
                        mEnabledFunctions.add(functionName);
                    } else {
                        mDisabledFunctions.add(functionName);
                    }
                }
            } else {
                Slog.w(TAG, "This kernel has not enabled USB composite class support");
            }
        } catch (FileNotFoundException e) {
            Slog.w(TAG, "This kernel does not have USB composite class support");
        } catch (Exception e) {
            Slog.e(TAG, "" , e);
        }
    }

    void systemReady() {
        synchronized (this) {
            update();
            mSystemReady = true;
        }
    }

    private final void update() {
        mHandler.sendEmptyMessage(MSG_UPDATE);
    }

    private final Handler mHandler = new Handler() {
        private void addEnabledFunctions(Intent intent) {
            // include state of all USB functions in our extras
            for (int i = 0; i < mEnabledFunctions.size(); i++) {
                intent.putExtra(mEnabledFunctions.get(i), Usb.USB_FUNCTION_ENABLED);
            }
            for (int i = 0; i < mDisabledFunctions.size(); i++) {
                intent.putExtra(mDisabledFunctions.get(i), Usb.USB_FUNCTION_DISABLED);
            }
        }

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MSG_UPDATE:
                    synchronized (this) {
                        final ContentResolver cr = mContext.getContentResolver();

                        if (Settings.Secure.getInt(cr,
                                Settings.Secure.DEVICE_PROVISIONED, 0) == 0) {
                            Slog.i(TAG, "Device not provisioned, skipping USB broadcast");
                            return;
                        }
                        // Send an Intent containing connected/disconnected state
                        // and the enabled/disabled state of all USB functions
                        Intent intent;
                        boolean usbConnected = (mUsbConfig != 0);
                        if (usbConnected) {
                            intent = new Intent(Usb.ACTION_USB_CONNECTED);
                            addEnabledFunctions(intent);
                        } else {
                            intent = new Intent(Usb.ACTION_USB_DISCONNECTED);
                        }
                        mContext.sendBroadcast(intent);

                        // send a sticky broadcast for clients interested in both connect and disconnect
                        intent = new Intent(Usb.ACTION_USB_STATE);
                        intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
                        intent.putExtra(Usb.USB_CONNECTED, usbConnected);
                        addEnabledFunctions(intent);
                        mContext.sendStickyBroadcast(intent);
                    }
                    break;
            }
        }
    };
}