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

Commit 98294e50 authored by Ying Wang's avatar Ying Wang
Browse files

Move android-common to framework/ex

This is one necessary step by unbundling.

Change-Id: I9d922a52374ad6331fa2e39fa4b5e16ad7d108fa
parent d103af4f
Loading
Loading
Loading
Loading

common/Android.mk

deleted100644 → 0
+0 −32
Original line number Diff line number Diff line
# Copyright (C) 2009 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.

LOCAL_PATH := $(call my-dir)

# Note: the source code is in java/, not src/, because this code is also part of
# the framework library, and build/core/pathmap.mk expects a java/ subdirectory.

include $(CLEAR_VARS)
LOCAL_MODULE := android-common
LOCAL_SDK_VERSION := current
LOCAL_SRC_FILES := \
     $(call all-java-files-under, java) \
     $(call all-logtags-files-under, java)
include $(BUILD_STATIC_JAVA_LIBRARY)

# Include this library in the build server's output directory
$(call dist-for-goals, droidcore, $(LOCAL_BUILT_MODULE):android-common.jar)

# Build the test package
include $(call all-makefiles-under, $(LOCAL_PATH))
+0 −167
Original line number Diff line number Diff line
/*
 * Copyright (C) 2006 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.common;

import android.database.AbstractCursor;
import android.database.CursorWindow;

import java.lang.System;
import java.util.ArrayList;

/**
 * A convenience class that presents a two-dimensional ArrayList
 * as a Cursor.
 * @deprecated This is has been replaced by MatrixCursor.
*/
public class ArrayListCursor extends AbstractCursor {
    private String[] mColumnNames;
    private ArrayList<Object>[] mRows;

    @SuppressWarnings({"unchecked"})
    public ArrayListCursor(String[] columnNames, ArrayList<ArrayList> rows) {
        int colCount = columnNames.length;
        boolean foundID = false;
        // Add an _id column if not in columnNames
        for (int i = 0; i < colCount; ++i) {
            if (columnNames[i].compareToIgnoreCase("_id") == 0) {
                mColumnNames = columnNames;
                foundID = true;
                break;
            }
        }

        if (!foundID) {
            mColumnNames = new String[colCount + 1];
            System.arraycopy(columnNames, 0, mColumnNames, 0, columnNames.length);
            mColumnNames[colCount] = "_id";
        }

        int rowCount = rows.size();
        mRows = new ArrayList[rowCount];

        for (int i = 0; i < rowCount; ++i) {
            mRows[i] = rows.get(i);
            if (!foundID) {
                mRows[i].add(i);
            }
        }
    }

    @Override
    public void fillWindow(int position, CursorWindow window) {
        if (position < 0 || position > getCount()) {
            return;
        }

        window.acquireReference();
        try {
            int oldpos = mPos;
            mPos = position - 1;
            window.clear();
            window.setStartPosition(position);
            int columnNum = getColumnCount();
            window.setNumColumns(columnNum);
            while (moveToNext() && window.allocRow()) {
                for (int i = 0; i < columnNum; i++) {
                    final Object data = mRows[mPos].get(i);
                    if (data != null) {
                        if (data instanceof byte[]) {
                            byte[] field = (byte[]) data;
                            if (!window.putBlob(field, mPos, i)) {
                                window.freeLastRow();
                                break;
                            }
                        } else {
                            String field = data.toString();
                            if (!window.putString(field, mPos, i)) {
                                window.freeLastRow();
                                break;
                            }
                        }
                    } else {
                        if (!window.putNull(mPos, i)) {
                            window.freeLastRow();
                            break;
                        }
                    }
                }
            }

            mPos = oldpos;
        } catch (IllegalStateException e){
            // simply ignore it
        } finally {
            window.releaseReference();
        }
    }

    @Override
    public int getCount() {
        return mRows.length;
    }

    @Override
    public String[] getColumnNames() {
        return mColumnNames;
    }

    @Override
    public byte[] getBlob(int columnIndex) {
        return (byte[]) mRows[mPos].get(columnIndex);
    }

    @Override
    public String getString(int columnIndex) {
        Object cell = mRows[mPos].get(columnIndex);
        return (cell == null) ? null : cell.toString();
    }

    @Override
    public short getShort(int columnIndex) {
        Number num = (Number) mRows[mPos].get(columnIndex);
        return num.shortValue();
    }

    @Override
    public int getInt(int columnIndex) {
        Number num = (Number) mRows[mPos].get(columnIndex);
        return num.intValue();
    }

    @Override
    public long getLong(int columnIndex) {
        Number num = (Number) mRows[mPos].get(columnIndex);
        return num.longValue();
    }

    @Override
    public float getFloat(int columnIndex) {
        Number num = (Number) mRows[mPos].get(columnIndex);
        return num.floatValue();
    }

    @Override
    public double getDouble(int columnIndex) {
        Number num = (Number) mRows[mPos].get(columnIndex);
        return num.doubleValue();
    }

    @Override
    public boolean isNull(int columnIndex) {
        return mRows[mPos].get(columnIndex) == null;
    }
}
+0 −100
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.

option java_package com.android.common

#####
# This file contains definitions for event log (android.util.EventLog) tags
# used by Google Mobile Services applications.  These definitions are part of
# the platform even when the Google applications are not.
#
# See system/core/logcat/event.logtags for a description of the file format.
#
# These event log tags must be assigned specific numbers (no "?") in the range
# 200000-300000.  If new tags are added, be aware that older platforms will be
# missing the tag definitions, and may not be able to show them in their logs.

#####
# System Update (OTA)

# System update status bits
# [31- 9] Reserved for future use
# [ 8- 7] package verified (0=not attempted, 1=succeeded, 2=failed)
# [    6] install approved
# [    5] download approved
# [ 4- 0] status
201001 system_update (status|1|5),(download_result|1|5),(bytes|2|2),(url|3)
201002 system_update_user (action|3)

#####
# Android Market

# @param changes Number of changes made to database in reconstruct
202001 vending_reconstruct (changes|1)

#####
# Google Services Framework

203001 sync_details (authority|3),(send|1|2),(recv|1|2),(details|3)

203002 google_http_request (elapsed|2|3),(status|1),(appname|3),(reused|1)

#####
# Google Talk Service

# This event is logged when GTalkService encounters important events
204001 gtalkservice (eventType|1)
# This event is logged for GTalk connection state changes. The status field is an int, but
# it really contains 4 separate values, each taking up a byte
#     (eventType << 24) + (connection state << 16) + (connection error << 8) + network state
204002 gtalk_connection (status|1)

# This event is logged when GTalk connection is closed.
# The status field is an int, but contains 2 different values, it's represented as
#
#     (networkType << 8) + connection error
#
# the possible error values are
#
# no_error=0, no_network=1, connection_failed=2, unknown_host=3, auth_failed=4,
# auth_expired=5, heart_beat_timeout=6, server_error=7, server_reject_rate_limiting=8, unknown=10
#
# duration is the connection duration.
204003 gtalk_conn_close (status|1),(duration|1)

# This event is logged for GTalk heartbeat resets
# interval_and_nt contains both the heartbeat interval and the network type, It's represented as
#     (networkType << 16) + interval
# interval is in seconds; network type can be 0 (mobile) or 1 (wifi); ip is the host ip addr.
204004 gtalk_heartbeat_reset (interval_and_nt|1),(ip|3)

# This event is logged when an Rmq v2 packet is sent or received.
204005 c2dm (packet_type|1),(persistent_id|3),(stream_id|1),(last_stream_id|1)

#####
# Google Login Service and Setup Wizard

# This event is for when communicating to the server times out during account setup
205001 setup_server_timeout
205002 setup_required_captcha (action|3)
205003 setup_io_error (status|3)
205004 setup_server_error
205005 setup_retries_exhausted
205006 setup_no_data_network
205007 setup_completed

205008 gls_account_tried (status|1)
205009 gls_account_saved (status|1)
205010 gls_authenticate (status|1),(service|3)
205011 google_mail_switch (direction|1)
+0 −224
Original line number Diff line number Diff line
/*
 * Copyright (C) 2006 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.common;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import java.util.HashMap;
import java.util.Iterator;

/**
 * A wrapper for a broadcast receiver that provides network connectivity
 * state information, independent of network type (mobile, Wi-Fi, etc.).
 * @deprecated Code tempted to use this class should simply listen for connectivity intents
 * (or poll ConnectivityManager) directly.
 * {@hide}
 */
public class NetworkConnectivityListener {
    private static final String TAG = "NetworkConnectivityListener";
    private static final boolean DBG = false;

    private Context mContext;
    private HashMap<Handler, Integer> mHandlers = new HashMap<Handler, Integer>();
    private State mState;
    private boolean mListening;
    private String mReason;
    private boolean mIsFailover;

    /** Network connectivity information */
    private NetworkInfo mNetworkInfo;

    /**
     * In case of a Disconnect, the connectivity manager may have
     * already established, or may be attempting to establish, connectivity
     * with another network. If so, {@code mOtherNetworkInfo} will be non-null.
     */
    private NetworkInfo mOtherNetworkInfo;

    private ConnectivityBroadcastReceiver mReceiver;

    private class ConnectivityBroadcastReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();

            if (!action.equals(ConnectivityManager.CONNECTIVITY_ACTION) ||
                mListening == false) {
                Log.w(TAG, "onReceived() called with " + mState.toString() + " and " + intent);
                return;
            }

            boolean noConnectivity =
                intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);

            if (noConnectivity) {
                mState = State.NOT_CONNECTED;
            } else {
                mState = State.CONNECTED;
            }

            mNetworkInfo = (NetworkInfo)
                intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
            mOtherNetworkInfo = (NetworkInfo)
                intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);

            mReason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON);
            mIsFailover =
                intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);

            if (DBG) {
                Log.d(TAG, "onReceive(): mNetworkInfo=" + mNetworkInfo +  " mOtherNetworkInfo = "
                        + (mOtherNetworkInfo == null ? "[none]" : mOtherNetworkInfo +
                        " noConn=" + noConnectivity) + " mState=" + mState.toString());
            }

            // Notifiy any handlers.
            Iterator<Handler> it = mHandlers.keySet().iterator();
            while (it.hasNext()) {
                Handler target = it.next();
                Message message = Message.obtain(target, mHandlers.get(target));
                target.sendMessage(message);
            }
        }
    };

    public enum State {
        UNKNOWN,

        /** This state is returned if there is connectivity to any network **/
        CONNECTED,
        /**
         * This state is returned if there is no connectivity to any network. This is set
         * to true under two circumstances:
         * <ul>
         * <li>When connectivity is lost to one network, and there is no other available
         * network to attempt to switch to.</li>
         * <li>When connectivity is lost to one network, and the attempt to switch to
         * another network fails.</li>
         */
        NOT_CONNECTED
    }

    /**
     * Create a new NetworkConnectivityListener.
     */
    public NetworkConnectivityListener() {
        mState = State.UNKNOWN;
        mReceiver = new ConnectivityBroadcastReceiver();
    }

    /**
     * This method starts listening for network connectivity state changes.
     * @param context
     */
    public synchronized void startListening(Context context) {
        if (!mListening) {
            mContext = context;

            IntentFilter filter = new IntentFilter();
            filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
            context.registerReceiver(mReceiver, filter);
            mListening = true;
        }
    }

    /**
     * This method stops this class from listening for network changes.
     */
    public synchronized void stopListening() {
        if (mListening) {
            mContext.unregisterReceiver(mReceiver);
            mContext = null;
            mNetworkInfo = null;
            mOtherNetworkInfo = null;
            mIsFailover = false;
            mReason = null;
            mListening = false;
        }
    }

    /**
     * This methods registers a Handler to be called back onto with the specified what code when
     * the network connectivity state changes.
     *
     * @param target The target handler.
     * @param what The what code to be used when posting a message to the handler.
     */
    public void registerHandler(Handler target, int what) {
        mHandlers.put(target, what);
    }

    /**
     * This methods unregisters the specified Handler.
     * @param target
     */
    public void unregisterHandler(Handler target) {
        mHandlers.remove(target);
    }

    public State getState() {
        return mState;
    }

    /**
     * Return the NetworkInfo associated with the most recent connectivity event.
     * @return {@code NetworkInfo} for the network that had the most recent connectivity event.
     */
    public NetworkInfo getNetworkInfo() {
        return mNetworkInfo;
    }

    /**
     * If the most recent connectivity event was a DISCONNECT, return
     * any information supplied in the broadcast about an alternate
     * network that might be available. If this returns a non-null
     * value, then another broadcast should follow shortly indicating
     * whether connection to the other network succeeded.
     *
     * @return NetworkInfo
     */
    public NetworkInfo getOtherNetworkInfo() {
        return mOtherNetworkInfo;
    }

    /**
     * Returns true if the most recent event was for an attempt to switch over to
     * a new network following loss of connectivity on another network.
     * @return {@code true} if this was a failover attempt, {@code false} otherwise.
     */
    public boolean isFailover() {
        return mIsFailover;
    }

    /**
     * An optional reason for the connectivity state change may have been supplied.
     * This returns it.
     * @return the reason for the state change, if available, or {@code null}
     * otherwise.
     */
    public String getReason() {
        return mReason;
    }
}
+0 −348

File deleted.

Preview size limit exceeded, changes collapsed.

Loading