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

Commit 35eef702 authored by Jeff Hamilton's avatar Jeff Hamilton
Browse files

Remove the unused demo data set stuff.

Change-Id: I81f7a8118876ee7cb6c356c63b0d0613d9777d4f
parent 1c11015e
Loading
Loading
Loading
Loading
+0 −140
Original line number Diff line number Diff line
/*
 * Copyright (C) 2007 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.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.net.Uri;
import android.os.Environment;
import android.provider.Contacts;
import android.provider.Settings;
import android.provider.MediaStore.Images;
import android.util.Config;
import android.util.Slog;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.OutputStream;

public class DemoDataSet
{
    private final static String LOG_TAG = "DemoDataSet";

    private ContentResolver mContentResolver;

    public final void add(Context context)
    {
        mContentResolver = context.getContentResolver();

        // Remove all the old data
        mContentResolver.delete(Contacts.People.CONTENT_URI, null, null);

        // Add the new data
        addDefaultData();
        
        // Add images from /android/images
        addDefaultImages();
    }

    private final void addDefaultImages()
    {
        File rootDirectory = Environment.getRootDirectory();
        String [] files
            = new File(rootDirectory, "images").list();
        int count = files.length;

        if (count == 0) {
            Slog.i(LOG_TAG, "addDefaultImages: no images found!");
            return;
        }

        for (int i = 0; i < count; i++)
        {
            String name = files[i];
            String path = rootDirectory + "/" + name;
            
            try {
                Images.Media.insertImage(mContentResolver, path, name, null);
            } catch (FileNotFoundException e) {
                Slog.e(LOG_TAG, "Failed to import image " + path, e);
            }
        }
    }
    
    private final void addDefaultData()
    {
        Slog.i(LOG_TAG, "Adding default data...");

//       addImage("Violet", "images/violet.png");
//       addImage("Corky", "images/corky.png");

        // PENDING: should this be done here?!?!
        Intent intent = new Intent(
                Intent.ACTION_CALL, Uri.fromParts("voicemail", "", null));
        addShortcut("1", intent);
    }

    private final Uri addImage(String name, Uri file)
    {
        ContentValues imagev = new ContentValues();
        imagev.put("name", name);

        Uri url = null;

        AssetManager ass = AssetManager.getSystem();
        InputStream in = null;
        OutputStream out = null;
        
        try
        {
            in = ass.open(file.toString());

            url = mContentResolver.insert(Images.Media.INTERNAL_CONTENT_URI, imagev);
            out = mContentResolver.openOutputStream(url);

            final int size = 8 * 1024;
            byte[] buf = new byte[size];

            int count = 0;
            do
            {
                count = in.read(buf, 0, size);
                if (count > 0) {
                    out.write(buf, 0, count);
                }
            } while (count > 0);
        }
        catch (Exception e)
        {
            Slog.e(LOG_TAG, "Failed to insert image '" + file + "'", e);
            url = null;
        }

        return url;
    }

    private final Uri addShortcut(String shortcut, Intent intent)
    {
        if (Config.LOGV) Slog.v(LOG_TAG, "addShortcut: shortcut=" + shortcut + ", intent=" + intent);
        return Settings.Bookmarks.add(mContentResolver, intent, null, null,
                                      shortcut != null ? shortcut.charAt(0) : 0, 0);
    }
}
+10 −48
Original line number Diff line number Diff line
@@ -16,34 +16,34 @@

package com.android.server;

import com.android.server.am.ActivityManagerService;
import com.android.server.status.StatusBarManagerService;
import com.android.internal.os.BinderInternal;
import com.android.internal.os.SamplingProfilerIntegration;
import com.android.server.am.ActivityManagerService;
import com.android.server.status.StatusBarService;

import dalvik.system.VMRuntime;
import dalvik.system.Zygote;

import android.accounts.AccountManagerService;
import android.app.ActivityManagerNative;
import android.bluetooth.BluetoothAdapter;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.ContentService;
import android.content.Context;
import android.content.Intent;
import android.content.pm.IPackageManager;
import android.database.ContentObserver;
import android.database.Cursor;
import android.media.AudioService;
import android.os.*;
import android.provider.Contacts.People;
import android.os.Looper;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.provider.Settings;
import android.server.BluetoothA2dpService;
import android.server.BluetoothService;
import android.server.search.SearchManagerService;
import android.util.EventLog;
import android.util.Slog;
import android.accounts.AccountManagerService;

import java.io.File;
import java.util.Timer;
@@ -51,11 +51,8 @@ import java.util.TimerTask;

class ServerThread extends Thread {
    private static final String TAG = "SystemServer";
    private final static boolean INCLUDE_DEMO = false;

    private static final int LOG_BOOT_PROGRESS_SYSTEM_RUN = 3010;

    private ContentResolver mContentResolver;
    ContentResolver mContentResolver;

    private class AdbSettingsObserver extends ContentObserver {
        public AdbSettingsObserver() {
@@ -329,11 +326,6 @@ class ServerThread extends Thread {
                Slog.e(TAG, "Failure starting Search Service", e);
            }

            if (INCLUDE_DEMO) {
                Slog.i(TAG, "Installing demo data...");
                (new DemoThread(context)).start();
            }

            try {
                Slog.i(TAG, "DropBox Service");
                ServiceManager.addService(Context.DROPBOX_SERVICE,
@@ -504,37 +496,7 @@ class ServerThread extends Thread {
    }
}

class DemoThread extends Thread
{
    DemoThread(Context context)
    {
        mContext = context;
    }

    @Override
    public void run()
    {
        try {
            Cursor c = mContext.getContentResolver().query(People.CONTENT_URI, null, null, null, null);
            boolean hasData = c != null && c.moveToFirst();
            if (c != null) {
                c.deactivate();
            }
            if (!hasData) {
                DemoDataSet dataset = new DemoDataSet();
                dataset.add(mContext);
            }
        } catch (Throwable e) {
            Slog.e("SystemServer", "Failure installing demo data", e);
        }

    }

    Context mContext;
}

public class SystemServer
{
public class SystemServer {
    private static final String TAG = "SystemServer";

    public static final int FACTORY_TEST_OFF = 0;