Projects >> platform_frameworks_base >>f450fd6af61248b90ddb9ed0bb9780c0d3378029

Chunk
Conflicting content
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
<<<<<<< HEAD
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicBoolean;
import java.io.FileDescriptor;
import java.io.PrintWriter;
=======
import java.util.regex.Pattern;
import java.util.UUID;
>>>>>>> aa1fd70100d1af393c8d4ebe9cb36a8fa15a3633

import com.android.internal.app.IBatteryStats;
import com.android.internal.util.AsyncChannel;
Solution content
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicBoolean;
import java.io.FileDescriptor;
import java.io.PrintWriter;

import com.android.internal.app.IBatteryStats;
import com.android.internal.util.AsyncChannel;
File
WifiService.java
Developer's decision
Version 1
Kind of conflict
Import
Chunk
Conflicting content
     * The icon to show in the 'available networks' notification. This will also
     * be the ID of the Notification given to the NotificationManager.
     */
<<<<<<< HEAD
    private static final int ICON_NETWORKS_AVAILABLE =
            com.android.internal.R.drawable.stat_notify_wifi_in_range;
    /**
     * When a notification is shown, we wait this amount before possibly showing it again.
=======
    private static final int DEFAULT_WAKELOCK_TIMEOUT = 8000;

    // Wake lock used by driver-stop operation
    private static PowerManager.WakeLock sDriverStopWakeLock;
    // Wake lock used by other operations
    private static PowerManager.WakeLock sWakeLock;

    private static final int MESSAGE_ENABLE_WIFI        = 0;
    private static final int MESSAGE_DISABLE_WIFI       = 1;
    private static final int MESSAGE_STOP_WIFI          = 2;
    private static final int MESSAGE_START_WIFI         = 3;
    private static final int MESSAGE_RELEASE_WAKELOCK   = 4;
    private static final int MESSAGE_UPDATE_STATE       = 5;
    private static final int MESSAGE_START_ACCESS_POINT = 6;
    private static final int MESSAGE_STOP_ACCESS_POINT  = 7;
    private static final int MESSAGE_SET_CHANNELS       = 8;
    private static final int MESSAGE_ENABLE_NETWORKS    = 9;
    private static final int MESSAGE_START_SCAN         = 10;
    private static final int MESSAGE_REPORT_WORKSOURCE  = 11;
    private static final int MESSAGE_ENABLE_RSSI_POLLING = 12;
    private static final int MESSAGE_WRITE_WIFI_AP_CONFIG = 13;
    private static final int MESSAGE_READ_WIFI_AP_CONFIG = 14;


    private final  WifiHandler mWifiHandler;

    /*
     * Cache of scan results objects (size is somewhat arbitrary)
>>>>>>> aa1fd70100d1af393c8d4ebe9cb36a8fa15a3633
     */
    private final long NOTIFICATION_REPEAT_DELAY_MS;
    /**
Solution content
     * The icon to show in the 'available networks' notification. This will also
     * be the ID of the Notification given to the NotificationManager.
     */
    private static final int ICON_NETWORKS_AVAILABLE =
            com.android.internal.R.drawable.stat_notify_wifi_in_range;
    /**
     * When a notification is shown, we wait this amount before possibly showing it again.
     */
    private final long NOTIFICATION_REPEAT_DELAY_MS;
    /**
File
WifiService.java
Developer's decision
Version 1
Kind of conflict
Attribute
Comment
Chunk
Conflicting content
            mWsmChannel.connect(mContext, this, mWifiStateMachine.getHandler());
        }

<<<<<<< HEAD
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: {
                    if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
                        mWifiStateMachineChannel = mWsmChannel;
                    } else {
                        Slog.e(TAG, "WifiStateMachine connection failure, error=" + msg.arg1);
                        mWifiStateMachineChannel = null;
                    }
                    break;
                }
                default: {
                    Slog.d(TAG, "WifiStateMachineHandler.handleMessage ignoring msg=" + msg);
                    break;
                }
            }
        }
    }
    WifiStateMachineHandler mWifiStateMachineHandler;
=======
    private static final String WIFIAP_CONFIG_FILE = Environment.getDataDirectory() +
            "/misc/wifi/softap.conf";

    private static final int WIFIAP_CONFIG_VERSION = 1;
    private WifiConfiguration mWifiApConfig = new WifiConfiguration();
    private final Object mWifiApConfigLock = new Object();

    WifiService(Context context, WifiStateTracker tracker) {
        mContext = context;
        mWifiStateTracker = tracker;
        mWifiStateTracker.enableRssiPolling(true);
        mBatteryStats = BatteryStatsService.getService();
>>>>>>> aa1fd70100d1af393c8d4ebe9cb36a8fa15a3633

    /**
     * Temporary for computing UIDS that are responsible for starting WIFI.
Solution content
            mWsmChannel.connect(mContext, this, mWifiStateMachine.getHandler());
        }

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: {
                    if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
                        mWifiStateMachineChannel = mWsmChannel;
                    } else {
                        Slog.e(TAG, "WifiStateMachine connection failure, error=" + msg.arg1);
                        mWifiStateMachineChannel = null;
                    }
                    break;
                }
                default: {
                    Slog.d(TAG, "WifiStateMachineHandler.handleMessage ignoring msg=" + msg);
                    break;
                }
            }
        }
    }
    WifiStateMachineHandler mWifiStateMachineHandler;

    /**
     * Temporary for computing UIDS that are responsible for starting WIFI.
File
WifiService.java
Developer's decision
Version 1
Kind of conflict
Annotation
Attribute
Method declaration
Method invocation
Method signature
Variable
Chunk
Conflicting content
        mAsyncServiceHandler = new AsyncServiceHandler(wifiThread.getLooper());
        mWifiStateMachineHandler = new WifiStateMachineHandler(wifiThread.getLooper());

<<<<<<< HEAD
        // Setting is in seconds
        NOTIFICATION_REPEAT_DELAY_MS = Settings.Secure.getInt(context.getContentResolver(),
                Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, 900) * 1000l;
        mNotificationEnabledSettingObserver = new NotificationEnabledSettingObserver(new Handler());
        mNotificationEnabledSettingObserver.register();

        mBackgroundScanSupported = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_wifi_background_scan_support);
=======
                }
            },new IntentFilter(ConnectivityManager.ACTION_TETHER_STATE_CHANGED));

        //Initiate a read of Wifi Ap configuration
        Message.obtain(mWifiHandler, MESSAGE_READ_WIFI_AP_CONFIG).sendToTarget();
>>>>>>> aa1fd70100d1af393c8d4ebe9cb36a8fa15a3633
    }

    /**
Solution content
        mAsyncServiceHandler = new AsyncServiceHandler(wifiThread.getLooper());
        mWifiStateMachineHandler = new WifiStateMachineHandler(wifiThread.getLooper());

        // Setting is in seconds
        NOTIFICATION_REPEAT_DELAY_MS = Settings.Secure.getInt(context.getContentResolver(),
                Settings.Secure.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY, 900) * 1000l;
        mNotificationEnabledSettingObserver = new NotificationEnabledSettingObserver(new Handler());
        mNotificationEnabledSettingObserver.register();

        mBackgroundScanSupported = mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_wifi_background_scan_support);
    }

    /**
File
WifiService.java
Developer's decision
Version 1
Kind of conflict
Attribute
Comment
Method invocation
Chunk
Conflicting content
     */
    public int getWifiApEnabledState() {
        enforceAccessPermission();
<<<<<<< HEAD
        return mWifiStateMachine.syncGetWifiApState();
    }

    /**
     * see {@link WifiManager#getWifiApConfiguration()}
     * @return soft access point configuration
     */
    public synchronized WifiConfiguration getWifiApConfiguration() {
        final ContentResolver cr = mContext.getContentResolver();
        WifiConfiguration wifiConfig = new WifiConfiguration();
        int authType;
        try {
            wifiConfig.SSID = Settings.Secure.getString(cr, Settings.Secure.WIFI_AP_SSID);
            if (wifiConfig.SSID == null)
                return null;
            authType = Settings.Secure.getInt(cr, Settings.Secure.WIFI_AP_SECURITY);
            wifiConfig.allowedKeyManagement.set(authType);
            wifiConfig.preSharedKey = Settings.Secure.getString(cr, Settings.Secure.WIFI_AP_PASSWD);
            return wifiConfig;
        } catch (Settings.SettingNotFoundException e) {
            Slog.e(TAG,"AP settings not found, returning");
            return null;
=======
        synchronized (mWifiApConfigLock) {
            WifiConfiguration config = new WifiConfiguration();
            config.SSID = mWifiApConfig.SSID;
            if (mWifiApConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
                config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
                config.preSharedKey = mWifiApConfig.preSharedKey;
            } else {
                config.allowedKeyManagement.set(KeyMgmt.NONE);
            }
            return config;
>>>>>>> aa1fd70100d1af393c8d4ebe9cb36a8fa15a3633
        }
    }
Solution content
     */
    public int getWifiApEnabledState() {
        enforceAccessPermission();
        return mWifiStateMachine.syncGetWifiApState();
    }

    /**
     * see {@link WifiManager#getWifiApConfiguration()}
     * @return soft access point configuration
     */
    public synchronized WifiConfiguration getWifiApConfiguration() {
        final ContentResolver cr = mContext.getContentResolver();
        WifiConfiguration wifiConfig = new WifiConfiguration();
        int authType;
        try {
            wifiConfig.SSID = Settings.Secure.getString(cr, Settings.Secure.WIFI_AP_SSID);
            if (wifiConfig.SSID == null)
                return null;
            authType = Settings.Secure.getInt(cr, Settings.Secure.WIFI_AP_SECURITY);
            wifiConfig.allowedKeyManagement.set(authType);
            wifiConfig.preSharedKey = Settings.Secure.getString(cr, Settings.Secure.WIFI_AP_PASSWD);
            return wifiConfig;
        } catch (Settings.SettingNotFoundException e) {
            Slog.e(TAG,"AP settings not found, returning");
            return null;
        }
    }
File
WifiService.java
Developer's decision
Version 1
Kind of conflict
Catch clause
Comment
If statement
Method invocation
Method signature
Return statement
Synchronized statement
Try statement
Variable
Chunk
Conflicting content
     */
    public synchronized void setWifiApConfiguration(WifiConfiguration wifiConfig) {
        enforceChangePermission();
<<<<<<< HEAD
        final ContentResolver cr = mContext.getContentResolver();
        if (wifiConfig == null)
            return;
        int authType = wifiConfig.getAuthType();
        Settings.Secure.putString(cr, Settings.Secure.WIFI_AP_SSID, wifiConfig.SSID);
        Settings.Secure.putInt(cr, Settings.Secure.WIFI_AP_SECURITY, authType);
        if (authType != KeyMgmt.NONE)
            Settings.Secure.putString(cr, Settings.Secure.WIFI_AP_PASSWD, wifiConfig.preSharedKey);
=======
        if (wifiConfig == null)
            return;
        Message.obtain(mWifiHandler, MESSAGE_WRITE_WIFI_AP_CONFIG, wifiConfig).sendToTarget();
    }

    /* Generate a default WPA2 based configuration with a random password.

       We are changing the Wifi Ap configuration storage from secure settings to a
       flat file accessible only by the system. A WPA2 based default configuration
       will keep the device secure after the update */
    private void setDefaultWifiApConfiguration() {
        synchronized (mWifiApConfigLock) {
            mWifiApConfig.SSID = mContext.getString(R.string.wifi_tether_configure_ssid_default);
            mWifiApConfig.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
            String randomUUID = UUID.randomUUID().toString();
            //first 12 chars from xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
            mWifiApConfig.preSharedKey = randomUUID.substring(0, 8) + randomUUID.substring(9,13);
        }
    }

    private void writeWifiApConfigBlocked(WifiConfiguration wifiConfig) {
        DataOutputStream out = null;
        try {
            out = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(WIFIAP_CONFIG_FILE)));

            out.writeInt(WIFIAP_CONFIG_VERSION);
            out.writeUTF(wifiConfig.SSID);
            if(wifiConfig.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
                out.writeInt(KeyMgmt.WPA_PSK);
                out.writeUTF(wifiConfig.preSharedKey);
            } else {
                out.writeInt(KeyMgmt.NONE);
            }
            synchronized (mWifiApConfigLock) {
                mWifiApConfig = wifiConfig;
            }
        } catch (IOException e) {
            Slog.e(TAG, "Error writing hotspot configuration" + e);
        } finally {
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {}
            }
        }
>>>>>>> aa1fd70100d1af393c8d4ebe9cb36a8fa15a3633
    }

    private void readWifiApConfigBlocked() {
Solution content
     */
    public synchronized void setWifiApConfiguration(WifiConfiguration wifiConfig) {
        enforceChangePermission();
        final ContentResolver cr = mContext.getContentResolver();
        if (wifiConfig == null)
            return;
        int authType = wifiConfig.getAuthType();
        Settings.Secure.putString(cr, Settings.Secure.WIFI_AP_SSID, wifiConfig.SSID);
        Settings.Secure.putInt(cr, Settings.Secure.WIFI_AP_SECURITY, authType);
        if (authType != KeyMgmt.NONE)
            Settings.Secure.putString(cr, Settings.Secure.WIFI_AP_PASSWD, wifiConfig.preSharedKey);
    }
File
WifiService.java
Developer's decision
Version 1
Kind of conflict
Comment
If statement
Method declaration
Method invocation
Method signature
Try statement
Variable
Chunk
Conflicting content
    /**
     * see {@link android.net.wifi.WifiManager#disconnect()}
     */
<<<<<<< HEAD
    public void disconnect() {
        enforceChangePermission();
        mWifiStateMachine.disconnectCommand();
=======
    private boolean setWifiApEnabledBlocking(boolean enable,
                                int uid, WifiConfiguration wifiConfig) {
        final int eventualWifiApState = enable ? WIFI_AP_STATE_ENABLED : WIFI_AP_STATE_DISABLED;

        if (mWifiApState == eventualWifiApState) {
            /* Configuration changed on a running access point */
            if(enable && (wifiConfig != null)) {
                try {
                    nwService.setAccessPoint(wifiConfig, mWifiStateTracker.getInterfaceName(),
                                             SOFTAP_IFACE);
                    setWifiApConfiguration(wifiConfig);
                    return true;
                } catch(Exception e) {
                    Slog.e(TAG, "Exception in nwService during AP restart");
                    try {
                        nwService.stopAccessPoint();
                    } catch (Exception ee) {
                        Slog.e(TAG, "Could not stop AP, :" + ee);
                    }
                    setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.DRIVER_UNLOAD);
                    return false;
                }
            } else {
                return true;
            }
        }

        /**
         * Fail AP if Wifi is enabled
         */
        if ((mWifiStateTracker.getWifiState() == WIFI_STATE_ENABLED) && enable) {
            setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.NO_DRIVER_UNLOAD);
            return false;
        }

        setWifiApEnabledState(enable ? WIFI_AP_STATE_ENABLING :
                                       WIFI_AP_STATE_DISABLING, uid, DriverAction.NO_DRIVER_UNLOAD);

        if (enable) {

            /* Use default config if there is no existing config */
            if (wifiConfig == null) wifiConfig = getWifiApConfiguration();

            if (!mWifiStateTracker.loadDriver()) {
                Slog.e(TAG, "Failed to load Wi-Fi driver for AP mode");
                setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.NO_DRIVER_UNLOAD);
                return false;
            }

            try {
                nwService.startAccessPoint(wifiConfig, mWifiStateTracker.getInterfaceName(),
                                           SOFTAP_IFACE);
            } catch(Exception e) {
                Slog.e(TAG, "Exception in startAccessPoint()");
                setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.DRIVER_UNLOAD);
                return false;
            }

            setWifiApConfiguration(wifiConfig);

        } else {

            try {
                nwService.stopAccessPoint();
            } catch(Exception e) {
                Slog.e(TAG, "Exception in stopAccessPoint()");
                setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.DRIVER_UNLOAD);
                return false;
            }

            if (!mWifiStateTracker.unloadDriver()) {
                Slog.e(TAG, "Failed to unload Wi-Fi driver for AP mode");
                setWifiApEnabledState(WIFI_AP_STATE_FAILED, uid, DriverAction.NO_DRIVER_UNLOAD);
                return false;
            }
        }

        setWifiApEnabledState(eventualWifiApState, uid, DriverAction.NO_DRIVER_UNLOAD);
        return true;
>>>>>>> aa1fd70100d1af393c8d4ebe9cb36a8fa15a3633
    }

    /**
Solution content
    /**
     * see {@link android.net.wifi.WifiManager#disconnect()}
     */
    public void disconnect() {
        enforceChangePermission();
        mWifiStateMachine.disconnectCommand();
    }

    /**
File
WifiService.java
Developer's decision
Version 1
Kind of conflict
Comment
If statement
Method invocation
Method signature
Return statement
Variable
Chunk
Conflicting content
                Settings.System.AIRPLANE_MODE_ON, 0) == 1;
    }

<<<<<<< HEAD
=======
    /**
     * Handler that allows posting to the WifiThread.
     */
    private class WifiHandler extends Handler {
        public WifiHandler(Looper looper) {
            super(looper);
        }

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {

                case MESSAGE_ENABLE_WIFI:
                    setWifiEnabledBlocking(true, msg.arg1 == 1, msg.arg2);
                    if (mWifiWatchdogService == null) {
                        mWifiWatchdogService = new WifiWatchdogService(mContext, mWifiStateTracker);
                    }
                    sWakeLock.release();
                    break;

                case MESSAGE_START_WIFI:
                    reportStartWorkSource();
                    mWifiStateTracker.setScanOnlyMode(msg.arg1 == WifiManager.WIFI_MODE_SCAN_ONLY);
                    mWifiStateTracker.restart();
                    mWifiStateTracker.setHighPerfMode(msg.arg1 ==
                            WifiManager.WIFI_MODE_FULL_HIGH_PERF);
                    sWakeLock.release();
                    break;

                case MESSAGE_UPDATE_STATE:
                    doUpdateWifiState();
                    break;

                case MESSAGE_DISABLE_WIFI:
                    // a non-zero msg.arg1 value means the "enabled" setting
                    // should be persisted
                    setWifiEnabledBlocking(false, msg.arg1 == 1, msg.arg2);
                    mWifiWatchdogService = null;
                    sWakeLock.release();
                    break;

                case MESSAGE_STOP_WIFI:
                    mWifiStateTracker.disconnectAndStop();
                    // don't release wakelock
                    break;

                case MESSAGE_RELEASE_WAKELOCK:
                    sDriverStopWakeLock.release();
                    break;

                case MESSAGE_START_ACCESS_POINT:
                    setWifiApEnabledBlocking(true,
                                             msg.arg1,
                                             (WifiConfiguration) msg.obj);
                    sWakeLock.release();
                    break;

                case MESSAGE_STOP_ACCESS_POINT:
                    setWifiApEnabledBlocking(false,
                                             msg.arg1,
                                             (WifiConfiguration) msg.obj);
                    sWakeLock.release();
                    break;

                case MESSAGE_SET_CHANNELS:
                    setNumAllowedChannelsBlocking(msg.arg1, msg.arg2 == 1);
                    break;

                case MESSAGE_ENABLE_NETWORKS:
                    mWifiStateTracker.enableAllNetworks(getConfiguredNetworks());
                    break;

                case MESSAGE_START_SCAN:
                    boolean forceActive = (msg.arg1 == 1);
                    switch (mWifiStateTracker.getSupplicantState()) {
                        case DISCONNECTED:
                        case INACTIVE:
                        case SCANNING:
                        case DORMANT:
                            break;
                        default:
                            mWifiStateTracker.setScanResultHandling(
                                    WifiStateTracker.SUPPL_SCAN_HANDLING_LIST_ONLY);
                            break;
                    }
                    mWifiStateTracker.scan(forceActive);
                    break;
                case MESSAGE_REPORT_WORKSOURCE:
                    reportStartWorkSource();
                    break;
                case MESSAGE_ENABLE_RSSI_POLLING:
                    mWifiStateTracker.enableRssiPolling(msg.arg1 == 1);
                    break;
                case MESSAGE_WRITE_WIFI_AP_CONFIG:
                    writeWifiApConfigBlocked((WifiConfiguration) msg.obj);
                    break;
                case MESSAGE_READ_WIFI_AP_CONFIG:
                    readWifiApConfigBlocked();
                    break;
            }
        }
    }

>>>>>>> aa1fd70100d1af393c8d4ebe9cb36a8fa15a3633
    @Override
    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
Solution content
                Settings.System.AIRPLANE_MODE_ON, 0) == 1;
    }

    @Override
    protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.DUMP)
File
WifiService.java
Developer's decision
Version 1
Kind of conflict
Class declaration
Comment