<commit_before>package com.robomorphine.remoteprefs;

import com.robomorphine.log.Log;
import com.robomorphine.log.tag.Tags;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public final class RemotePreferences {
    private static final String TAG = Tags.getTag(RemotePreferences.class);
    
    public static final String META_DATA_NAME = "com.robomorphine.remote.preferences";
    public static final int DEFAULT_ICON_SIZE_PX = 48;
    
    private final Context mContext;
    private final PackageManager mPackageManager;
    
    public RemotePreferences(Context context) {
        mContext = context.getApplicationContext();
        mPackageManager = mContext.getPackageManager();
    }
    
    public static Drawable makeGrayscale(Context context, Drawable drawable) {
        int width = drawable.getBounds().width();        
        int height = drawable.getBounds().height();    
                
        Resources res = context.getResources();
        int size = (int)res.getDimension(R.dimen.app_icon_size);
        if(width <= 0) {
            width = size;
        }
        
        if(height <= 0) {
            height = size;
        }
        
        Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, width, height);
        drawable.draw(canvas);
        
        /* apply grayscale transformation */
        for(int w = 0; w < width; w++) {
            for(int h = 0; h < height; h++) {
                int pixel = bitmap.getPixel(w, h);
                int avarage = Color.red(pixel) + Color.green(pixel) + Color.blue(pixel);
                avarage /= 3;
                pixel = Color.argb(255, avarage, avarage, avarage);
                bitmap.setPixel(w, h, pixel);
            }
        }
        BitmapDrawable result = new BitmapDrawable(res, bitmap);
        return result;
    }
    
    public List<AndroidPackage> getPackages() {
        
        int flags = PackageManager.GET_DISABLED_COMPONENTS |
                    PackageManager.GET_META_DATA | 
                    PackageManager.GET_PROVIDERS;
        
        List<PackageInfo> packages = mPackageManager.getInstalledPackages(flags);
        List<AndroidPackage> androidPackages = new ArrayList<AndroidPackage>(packages.size());
        
        /* List packages with matching providers */ 
        for(PackageInfo pkg : packages) {
                         
            ProviderInfo providerInfo = null;
            if(pkg.providers != null) {
                for(ProviderInfo provider : pkg.providers) {<commit_msg>Fixed bitmap desaturating: added alpha channel handling.<commit_after>package com.robomorphine.remoteprefs;

import com.robomorphine.log.Log;
import com.robomorphine.log.tag.Tags;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

public final class RemotePreferences {
    private static final String TAG = Tags.getTag(RemotePreferences.class);
    
    public static final String META_DATA_NAME = "com.robomorphine.remote.preferences";
    public static final int DEFAULT_ICON_SIZE_PX = 48;
    
    private final Context mContext;
    private final PackageManager mPackageManager;
    
    public RemotePreferences(Context context) {
        mContext = context.getApplicationContext();
        mPackageManager = mContext.getPackageManager();
    }
    
    public static Drawable makeGrayscale(Context context, Drawable drawable) {
        int width = drawable.getBounds().width();        
        int height = drawable.getBounds().height();    
                
        Resources res = context.getResources();
        int size = (int)res.getDimension(R.dimen.app_icon_size);
        if(width <= 0) {
            width = size;
        }
        
        if(height <= 0) {
            height = size;
        }
        
        Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, width, height);
        drawable.draw(canvas);
        
        /* apply grayscale transformation */
        for(int w = 0; w < width; w++) {
            for(int h = 0; h < height; h++) {
                int pixel = bitmap.getPixel(w, h);
                int avarage = Color.red(pixel) + Color.green(pixel) + Color.blue(pixel);
                int alpha = Color.alpha(pixel);
                avarage /= 3;
                pixel = Color.argb(alpha, avarage, avarage, avarage);
                bitmap.setPixel(w, h, pixel);
            }
        }
        BitmapDrawable result = new BitmapDrawable(res, bitmap);
        return result;
    }
    
    public List<AndroidPackage> getPackages() {
        
        int flags = PackageManager.GET_DISABLED_COMPONENTS |
                    PackageManager.GET_META_DATA | 
                    PackageManager.GET_PROVIDERS;
        
        List<PackageInfo> packages = mPackageManager.getInstalledPackages(flags);
        List<AndroidPackage> androidPackages = new ArrayList<AndroidPackage>(packages.size());
        
        /* List packages with matching providers */ 
        for(PackageInfo pkg : packages) {
                         
            ProviderInfo providerInfo = null;
            if(pkg.providers != null) {
                for(ProviderInfo provider : pkg.providers) {
{'fraction_non_alphanumeric': 0.09405543983336004, 'fraction_numerical': 0.004646691235378946, 'mean_word_length': 2.397931409907458, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3318780', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1668, 'n_words': 381}