<commit_before>/*
 * Copyright (C) 2012 OTA Updater
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * You may only use this file in compliance with the license and provided you are not associated with or are in co-operation anyone by the name '<NAME>'.
 * 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.updater.ota;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

import org.apache.http.client.ClientProtocolException;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.provider.Settings;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.gcm.GCMRegistrar;
import com.updater.ota.FetchRomInfoTask.RomInfoListener;

public class OTAUpdaterActivity extends PreferenceActivity {
    protected static final String NOTIF_ACTION = "com.updater.ota.action.NOTIF_ACTION";

    private boolean checkOnResume = false;

    /** Called when the activity is first created. */
    @Override
    @SuppressWarnings("deprecation")
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (!Utils.isROMSupported()) {
        	AlertDialog.Builder alert = new AlertDialog.Builder(this);
        	alert.setTitle(R.string.alert_unsupported_title);
        	alert.setMessage(R.string.alert_unsupported_message);
        	alert.setCancelable(false);
        	alert.setPositiveButton(R.string.alert_exit, new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
					finish();
				}
			});
        	alert.create().show();
        } else { 
            if (Utils.marketAvailable(this)) {
                GCMRegistrar.checkDevice(getApplicationContext());
                GCMRegistrar.checkManifest(getApplicationContext());
                final String regId = GCMRegistrar.getRegistrationId(getApplicationContext());
                if (regId.equals("")) {
                    GCMRegistrar.register(getApplicationContext(), "1068482628480");
                    Log.v("OTAUpdater::GCMRegister", "GCM registered");
                } else {
                    Log.v("OTAUpdater::GCMRegister", "Already registered");
                }
            } else {
                UpdateCheckReceiver.setAlarm(getApplicationContext());
                checkOnResume = true;
            }
    
            Intent i = getIntent();
            if (i.getAction().equals(NOTIF_ACTION)) {
            	showUpdateDialog(RomInfo.fromIntent(i));
            }
    
            addPreferencesFromResource(R.xml.main);
    
            if (Config.getInstance(getApplicationContext()).getPruneFiles()) {
                pruneFiles();
            }
    
            String buildDevice = android.os.Build.DEVICE.toLowerCase();
            String buildVer = android.os.Build.ID;
            String buildRom = android.os.Build.DISPLAY;
            String buildPrint = android.os.Build.FINGERPRINT;
    
            final Preference device = findPreference("device_view");
            device.setSummary(buildDevice);
            final Preference rom = findPreference("rom_view");
            rom.setSummary(buildRom);
            final Preference version = findPreference("version_view");
            version.setSummary(buildVer);
            final Preference build = findPreference("build_view");
            build.setSummary(buildPrint);
        }
    }

    @Override
    public void onResume() {
        super.onResume();

        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();
        if (!ni.isConnected()) {<commit_msg>misc. fixes<commit_after>/*
 * Copyright (C) 2012 OTA Updater
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * You may only use this file in compliance with the license and provided you are not associated with or are in co-operation anyone by the name '<NAME>'.
 * 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.updater.ota;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

import org.apache.http.client.ClientProtocolException;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.provider.Settings;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import com.google.android.gcm.GCMRegistrar;
import com.updater.ota.FetchRomInfoTask.RomInfoListener;

public class OTAUpdaterActivity extends PreferenceActivity {
    protected static final String NOTIF_ACTION = "com.updater.ota.action.NOTIF_ACTION";

    private boolean checkOnResume = false;
    private Config cfg;

    /** Called when the activity is first created. */
    @Override
    @SuppressWarnings("deprecation")
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        cfg = Config.getInstance(getApplicationContext());
        
        if (!Utils.isROMSupported()) {
        	AlertDialog.Builder alert = new AlertDialog.Builder(this);
        	alert.setTitle(R.string.alert_unsupported_title);
        	alert.setMessage(R.string.alert_unsupported_message);
        	alert.setCancelable(false);
        	alert.setPositiveButton(R.string.alert_exit, new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
					finish();
				}
			});
        	alert.create().show();
        } else { 
            if (Utils.marketAvailable(this)) {
                GCMRegistrar.checkDevice(getApplicationContext());
                GCMRegistrar.checkManifest(getApplicationContext());
                final String regId = GCMRegistrar.getRegistrationId(getApplicationContext());
                if (regId.length() != 0) {
                    if (cfg.upToDate()) {
                        Log.v("OTAUpdater::GCMRegister", "Already registered");
                    } else {
                        Log.v("OTAUpdater::GCMRegister", "Already registered, out-of-date, reregistering");
                        GCMRegistrar.unregister(getApplicationContext());
                        GCMRegistrar.register(getApplicationContext(), Config.GCM_SENDER_ID);
                        cfg.setValuesToCurrent();
                        Log.v("OTAUpdater::GCMRegister", "GCM registered");
                    }
                } else {
                    GCMRegistrar.register(getApplicationContext(), Config.GCM_SENDER_ID);
                    Log.v("OTAUpdater::GCMRegister", "GCM registered");
                }
            } else {
                UpdateCheckReceiver.setAlarm(getApplicationContext());
                checkOnResume = true;
            }

            addPreferencesFromResource(R.xml.main);
            
            Intent i = getIntent();
            if (i.getAction().equals(NOTIF_ACTION)) {
            	showUpdateDialog(RomInfo.fromIntent(i));
            }
    
            if (Config.getInstance(getApplicationContext()).getPruneFiles()) {
                pruneFiles();
            }
    
            String buildDevice = android.os.Build.DEVICE.toLowerCase();
            String buildVer = android.os.Build.ID;
            String buildRom = android.os.Build.DISPLAY;
            String buildPrint = android.os.Build.FINGERPRINT;
    
            final Preference device = findPreference("device_view");
            device.setSummary(buildDevice);
            final Preference rom = findPreference("rom_view");
            rom.setSummary(buildRom);
            final Preference version = findPreference("version_view");
            version.setSummary(buildVer);
            final Preference build = findPreference("build_view");
            build.setSummary(buildPrint);
        }
    }

    @Override
    public void onResume() {
        super.onResume();

        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();
        if (!ni.isConnected()) {
{'fraction_non_alphanumeric': 0.09614416591160777, 'fraction_numerical': 0.0030202355783751134, 'mean_word_length': 2.780060882800609, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3859944', 'n_tokens_mistral': 2681, 'n_tokens_neox': 2574, 'n_words': 598}